SQL
No description yet. This curated deck is ready for daily study.
Card preview (5)
SELECT
• Determines what fields you want to select, and therefore show in the final output. • You can either select individual field (separated by a comma) or all fields using an Asterisk (*).
FROM
• Indicates which table you are querying
WHERE
• The condition you are setting. • You don’t need to have this part if you don’t want to set a condition.
Q: Write the SQL to locate all the records where the wins is 14 (in the premier league table)
• The question does not specify which fields to pull out, therefore we will pull them all out. • SELECT * • Secondly, we now need to indicate which table we are using. • It is called Premier. • SELECT * FROM Premier • The question is asking us to locate the records where the wins is 14. • That is our condition, that the team must have 14 wins. • We need to know what the name of the field is where the wins are stored. • In this table it is called W. Here is our final SQL query with the condition now added: • SELECT * FROM Premier WHERE W = 14
Q: Write the SQL to locate all the team name and points where the losses is less than 11.
• In this question we have got specific fields to extract (team name and points). • In this table the team name is the field called club, and the points is called Pts. Here is our SQL query so far: • SELECT Club, Pts • Secondly, we now need to indicate which table we are using. • It is called Premier. • Here is our SQL query now with the FROM statement attached: • SELECT Club, Pts FROM Premier • The question is asking us to locate the records where the number of losses is less than 11. • That is our condition, that the team must have less than 11 losses. • We need to know what the name of the field is where the losses are stored. In this table it is called L. - Here is our final SQL query with the condition now added: • SELECT Club, Pts FROM Premier WHERE L < 11