We'll start with something simple. The general format for a SELECT statement is:
SELECT <column list> FROM <table list> WHERE <condition list>;Here's an example of how it can be used - the following SQL query retrieves all the records in table "a".
SELECT * FROM a;Here's the output:
+----+------+
| a1 | a2 |
+----+------+
| 10 | u |
| 20 | v |
| 30 | w |
| 40 | x |
| 50 | y |
| 60 | z |
+----+------+ I can filter out some of these records by adding a WHERE clause:
SELECT * FROM a WHERE a1 > 20;This returns
+----+------+
| a1 | a2 |
+----+------+
| 30 | w |
| 40 | x |
| 50 | y |
| 60 | z |
+----+------+ And I can even restrict the number of columns shown, by specifying a list of column names instead of the all-purpose asterisk:
SELECT a2 FROM a WHERE a1 > 20;Which gives me:
+------+
| a2 |
+------+
| w |
| x |
| y |
| z |
+------+
Please enable JavaScript to view the comments powered by Disqus. blog comments powered by