Order the result by gpa in descending order. SELECT * FROM class101 WHERE gpa > 4 AND name LIKE 'k%' ORDER BY gpa DESC, name ASC - Use AND, OR, NOT to combine simple conditions. wildcard _ matches one (any) character. wildcard % matches zero or more (any) characters SELECT name FROM class101 WHERE name LIKE 'k%' - Use "LIKE" to perform pattern-matching on strings, with SELECT name, gpa FROM class101 WHERE name = 'Tan Ah Teck' - Perform FULL-match on strings (= or !=). You can compare numbers (INT, FLOAT) using =, >, =, (!=) SELECT name, gpa FROM class101 WHERE gpa >= 4.7 - Select columns name and gpa from table class101, where the rows meet the criterion (gpa >= 4.7). The wildcard * denotes all the columns. SELECT * FROM class101 - Select ALL columns from table class101. FROM tableName WHERE criteria SELECT * FROM tableName WHERE criteria - EXAMPLES SELECT name, gpa FROM class101 - Select columns name and gpa from table class101. SQL (Structure Query Language) defines a set of intuitive commands (such as SELECT, INSERT, DELETE, UPDATE) to interact with relational database system. | id (INT) | name (VARCHAR(50)) | gpa (FLOAT) | We choose: INT (integer) for column id, VARCHAR(50) (variable-length string of up to 50 characters) for name, and FLOAT (floating-point number) for gpa. Suppose we have a database called studentdb, a table called class101 in the database with 3 columns ( id, name, gpa) and 4 rows as illustrated below.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |