SQL Commands X (1)
SQL Commands X (1)
My SQL Clauses:
11. FROM Clause: It is used to retrieve values from the specified table
Eg: SELECT * FROM <tablename>;
12. WHERE Clause: It is used to specify a condition to the query
Eg: SELECT * from <tablename> WHERE <condition>;
13. DISTINCT Clause: It is used to omit repeated values in the query result.
Eg. SELECT DISTINCT <columnname> FROM <tablename>;
14. BETWEEN Clause: It is used to specify the range from which values are to be queried.
Eg: SELECT * FROM <tablename>
WHERE <condition> BETWEEN <value1> AND <value2>;
15. LIKE Clause: It is used to search for a particular character or word and then run the query.
Eg: SELECT * FROM <tablename> WHERE <condition> LIKE ‘A%’;
(LIKE Clause has 3 types of searches.
1. “A%”: Means it will start from A
2. “%A”: Means it will end at A
3. “%A%”: Means the word or value contains the letter A.)
16. LIMIT Clause: It is used to limit the total number of rows.
Eg: SELECT * FROM <tablename> LIMIT 10; (It will show only 10 rows)
17. IN Clause: It is used to specify a condition in a list of values.
Eg: SELECT * FROM <tablename> WHERE <condition> IN (‘value1’, ‘value2’, ‘value3’);
18. GROUP BY clause: It is used to group the result rows into specific groups as specified by a column.
Eg: SELECT * FROM <tablename> GROUP BY <columnname>;
19. HAVING clause: It is used in conjunction with GROUP BY and restricts the grouped results by a
condition.
Eg: SELECT * FROM <tablename> GROUP BY <colname> HAVING <condition>;
20. ORDER BY clause: It is used to determine the order of appearance of rows after a query is
executed. ORDER BY can order by Ascending Order (ASC) of a specific column, Descending order
(DESC) of a specific column or by the values of a specific column.
Eg: SELECT * FROM <tablename> ORDER BY <columnname> ASC / DESC;