header
  • prevSection
  • prev
  • nextSection
  • Navigation Arrow
  • SQL
  • Navigation Arrow
  • DML
  • Navigation Arrow
  • Select

Data Manipulation Language (DML)

Select

Select is our main tool for interrogating our database and extracting information. The syntax for SELECT

SELECT {*|[column_name [AS column_alias]][,…]}
FROMtable_name[table_alias][,…]
[WHEREcondition]
[GROUP BYcolumn_list] [HAVING condition]
[ORDER BYcolumn_list]

As you can see there is a lot of options here. The SQL SELECT allows you to create sophisticated queries on the data in the database

A simple implementation of select statement might be

SELECT * FROMstudents

A slightly more advanced implementation of this might be

SELECTstudentId, firstName, lastName FROM students
FROMstudents
WHEREstudentId = 1;

Note that this selects the student id, first name and last name of the student who has the student id of 1. Notice the comma at the end of each column definition to separate the definitions

Having looked at a simple example of select statements, we will now look at a more complex example. In this next example we have a student database consisting of 2 tables, 1 containing contact details and other being the table we just gave an example of.

SELECTstudents.student_id,first_name,last_name,student_address
FROMstudents,student_contact AS contact
WHEREstudents.student_id = contact.student_id;

As you can see, the above example displays the student id, first name, last name and address of the student who has the same student id on both the students and contact tables.

  • prevSection
  • prev
  • nextSection
  • Navigation Arrow
  • SQL
  • Navigation Arrow
  • DML
  • Navigation Arrow
  • Select