Let us build a database '
test' with table 'person' inside it, having column name, age, gender. see how to do this
Insert a line into table:
This will add a new line or data into the table '
INSERT INTO person (name, gender) VALUES ('omphu', 'female')
person' on column name, gender with value omphu, female respectively and will leave the value of age blank.
Select line using WHERE:
SELECT * FROM person WHERE gender='female'
Select specific column:
This will output the value of column
SELECT name FROM person WHERE gender='male'
name where gender is female.
Specify more argument to refine search:
Will output result if this two condition are true,
SELECT name, age FROM person WHERE age='21' AND gender='male'
age & gender.
SELECT name, age FROM person where age='21' OR gender='female'
age & gender.
Limit output to 5 result:
SELECT * FROM person LIMIT 5
Sort result by Ascending/Descending order:
SELECT * FROM person ORDER BY name ASC
SELECT * FROM person ORDER BY name DESC
Query
name which contain the letter a.
SELECT * FROM person WHERE name LIKE '%a%'
Query only unique
This query is useful when we have many duplicate data of the same value.
name:
SELECT DISTINCT(name) FROM person
Count total line in the table:
SELECT COUNT(name) FROM person
No comments:
Post a Comment