Database constists of tables. Table is collections of rows, every row has one or more columns. Below is Genre table from Chinook sample database:
| GenreId | Name |
|---|---|
| 1 | Rock |
| 2 | Jazz |
| 3 | Metal |
| 4 | Alternative & Punk |
| 5 | Rock And Roll |
| 6 | Blues |
| 7 | Latin |
With SQL, you can select all rows from table Genre using following command:
SELECT * FROM Genre
SELECT command reads data from database. "*" denotes that all columns should be read. After FROM, source table follows. The same result you will obtain with command
SELECT GenreId, Name FROM Genre
In "Connection tree", you could see list of tables. If you select table in connection tree, you can see table structure in "Summary" tab.
SELECT statement has DISTINCT option, which causes that only unique rows are returned.
If you want to see all cities referenced from "Customer" table, you could use query:
SELECT DISTINCT City FROM Customer
You can specify order of result rows using ORDER BY clause. You could use option DESC for descending order. Opposite option is ASC (ascending), which can be as default value omited.
Syntax is:
SELECT columns FROM table ORDER BY column1 [DESC] [,column2 [DESC]]
SELECT * FROM Customer ORDER BY Country
SELECT * FROM Customer ORDER BY Country DESC, City ASC
Post new comment