Chapter 18 - Introduction to SQL Flashcards
What is SQL?
» SQL is a declarative language used to query and update tables in a relational database
What does the SELECT command do?
» Used to extract a collection of fields from a given table
What does the FROM command do?
» Specifies from which table the data will come from
What does the WHERE command do?
» Lists the search criteria
What does the ORDER BY command do?
» List the fields that the results are to be sorted on
What is one key feature to remember about the ORDER BY command?
» Default order is always ASC
What are the 2 types of commands in the ORDER BY statement?
» ASC
» DESC
What does the = command mean?
» Equal to
» Such as Title = “Death note”
What does the != command mean?
» Not equal to
What does the >= command mean?
» Greater than or equal to
What does the <= command mean?
» Less than or equal to
What does the IN command do?
» Equal to a value within a set of values
What is the LIKE command?
» Similiar to
What does the BETWEEN..AND command mean?
» Within a range
» Such as Datepublish BETWEEN 01 AND 31
What is the IS NULL operator?
» Field does not contain a value
What is the standard structure of a SQL query?
» SELECT
» FROM
» WHERE
» ORDER BY
What is the * operator?
» A wild card, selects all the fields of records
What are the commands to combine data from two or more tables, by only specifying which table the data is held in?
» Using the syntax:
» tablename.fieldname
» Then use multiple instances of this syntax to combine the tables
What is one thing to remember when joining data from two or more table?
» The table name is optional unless the field name appears in more than one table
How can you provide a link between tables in SQL?
» Using a condintion in the WHERE clause, such as eg..
» WHERE song.artistID = Artist.ArtistID
What is an alternative method of combining rows from two or more tables?
» Using the SQL JOIN command
When can the JOIN command be used?
» Can be used to combine data from two or more tables by specifying a common field between them
What is the main command of the JOIN operator?
» JOIN tablename
» ON tablename.field = tablename.field
» Note the table name is the other table which is not in the FROM statement
What is one key thing to remeber after using the JOIN command?
» Remember to specify the table where the field is coming from
» Usually just do the table in which it is in the FROM statement then dot the record which links the 2 tables
What is the main overall structure of the SQL query when there is a JOIN command?
» SELECT
» FROM
» JOIN
» ON
» WHERE