Syllabus Detail

  • Create a simple query. 11 GEN

Background

  • This article will show you some examples of simple queries using SQL
  • Each query will provide the database, table and column names necessary to perform the task
  • Try coming up with some of your own simple queries to test!

 

Select all students

This query will simply return all details about all students in our "Students" table.

  • Database name: myDatabase
  • Table name: Students
  • Query:
    • SELECT * FROM `Students`.`myDatabase`
  • Note: appending the database name to the table name isn't necessary and is up to the developer's preferences

 

View all the name's of male students

This query will return the first name (FirstName) and last name (LastName) of all students in a database with a "male" gender.

  • Database name: myDatabase
  • Table name: Students
  • Query:
    • SELECT `FirstName`, `LastName` FROM `Students`.`myDatabase` WHERE `Gender` = `Male`

 

Insert a new student

This query will insert a new student in to the Students table of our database.

  • Database name: myDatabase
  • Table name: Students
  • Query:
    • INSERT INTO `Students` VALUES(`John`, `Doe`, `Male`)

 

Update a student's record

This query will update a student's gender and change it to "Female".

  • Database name: myDatabase
  • Table name: Students
  • Query:
    • UPDATE `Students` SET `Gender` = `Female` WHERE `FirstName` = `Mary`

 

Delete a student record

This query will delete all records of students who have graduated according to our database.

  • Database name: myDatabase
  • Table name: Students
  • Query:
    • DELETE FROM `Students` WHERE `Schooling_Status` = `Graduated`

 

Further Research

  • View some more query examples by InformIT here
  • Starting with the basics by Microsoft here

 

Worksheet and Practice (yet to be added)

Found an error or have an enhancement? Please let us know via this contact form