Difference between revisions of "Select Queries"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 9: Line 9:
 
   ORDER BY `TABLE` ASC / DESC ;
 
   ORDER BY `TABLE` ASC / DESC ;
 
  </syntaxhighlight>
 
  </syntaxhighlight>
 +
 +
==Basic Example==
 +
 +
<syntaxhighlight lang=sql>
 +
SELECT *
 +
FROM  Book
 +
WHERE price > 100.00
 +
ORDER BY title;
 +
</syntaxhighlight>
 +
 +
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.

Revision as of 12:49, 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.