Difference between revisions of "Select Queries"
Line 13: | Line 13: | ||
<syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
− | SELECT * | + | SELECT * |
− | FROM Book | + | FROM Book |
− | WHERE price > 100.00 | + | WHERE price > 100.00 |
− | ORDER BY title; | + | ORDER BY title; |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 22: | Line 22: | ||
==Relational Databases & Select== | ==Relational Databases & Select== | ||
− | |||
− | |||
− | |||
− | |||
− | + | <syntaxhighlight lang=sql> | |
− | + | SELECT TutorGroup.Name, Student.Name | |
− | + | FROM TutorGroup, Student | |
− | + | WHERE Student.ID = TutorGroup.StudentID | |
− | + | AND Student.YearGroup = 12 AND Student.Gender = 'Male' | |
− | + | ORDER BY TutorGroup.Name; | |
+ | </syntaxhighlight> |
Revision as of 13:16, 17 December 2016
- Used for fetching information from an SQL database.
- 'Outputs' the data once successfully selected
- Allows selection from multiple tables but not multiple databases.
The Basic Construct
SELECT `data` FROM `TABLE`
WHERE `Condtion`
ORDER BY `TABLE` ASC / DESC ;
Basic Example
SELECT *
FROM Book
WHERE price > 100.00
ORDER BY title;
Remember the select can have * to select all fields, however questions will normally specify what fields to select. The from section should identify which table(s) to select the data from. The where section should include the criteria used to select the data, this could be a simple statement as above but remember you can also include other operators such as and, or, not, like, and so on.
Relational Databases & Select
SELECT TutorGroup.Name, Student.Name
FROM TutorGroup, Student
WHERE Student.ID = TutorGroup.StudentID
AND Student.YearGroup = 12 AND Student.Gender = 'Male'
ORDER BY TutorGroup.Name;