成人快手

Searching a database

Queries are a method of requesting information from a database. A specialised programming language called is often used to create that retrieve information from a database.

SQL allows a user to SELECT fields FROM a table WHERE certain criteria are met.

For example, from the table below, SELECT 'Firstname','Lastname' FROM 'Customer ID' WHERE 'Town = Belfast':

Customer IDFirstnameLastnameGenderAddressTown
C0AliceAndersonF13 Monk WayLisburn
C1BobBuchannonM14b Iris StreetBelfast
C2ConorCrawleyM17 Eblana StreetArmagh
C3DavinaDevlinF53 Fitzwilliam StNewry
C4EdwardEllisonM42 Park ViewEnniskillen
Customer IDC0
FirstnameAlice
LastnameAnderson
GenderF
Address13 Monk Way
TownLisburn
Customer IDC1
FirstnameBob
LastnameBuchannon
GenderM
Address14b Iris Street
TownBelfast
Customer IDC2
FirstnameConor
LastnameCrawley
GenderM
Address17 Eblana Street
TownArmagh
Customer IDC3
FirstnameDavina
LastnameDevlin
GenderF
Address53 Fitzwilliam St
TownNewry
Customer IDC4
FirstnameEdward
LastnameEllison
GenderM
Address42 Park View
TownEnniskillen

This would return: Bob Buchannon.

The criteria for a SELECT query can contain:

  • (AND, OR, NOT)
  • (<, >, =, <=, >=)

The results of a query will always be returned as a table.

Boolean operators

  • AND - Returns a record if both the first AND second condition is true
  • OR - Returns a record if either the first OR second condition is true
  • NOT - Only returns a record if the condition is NOT true

Comparison operators

  • > - Is one value greater than another?
  • < - Is one value less than another?
  • = - Is one value equal to another?
  • <= - Is one value less than OR equal to another?
  • >= - Is one value greater than OR equal to another?