FANDOM



The PQL AND & OR Operators

The AND operator displays a record if both the first condition and the second condition are true.
The OR operator displays a record if either the first condition or the second condition is true.

AND Operator Example

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville
2 Hamilton Braeburn Braeburn Orchard Appleloosa
3 Finish Photo Biba Boutique Canterlot
4 Macintosh Big Sweet Apple Acres Ponyville
5 Pie Inkie Pie Rock Farm Rambling Rock Ridge

Now we want to select only the ponies with the first name equal to "Pinkie" AND the last name equal to "Pie":

We use the following SELECT statement:

Spike: Please SELECT * FROM Ponies WHERE FirstName='Pinkie' AND LastName='Pie'

The result-set will look like this:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville



OR Operator Example

Now we want to select only the ponies with the first name equal to "Pinkie" OR the first name equal to "Photo":

We use the following SELECT statement:

Spike: Please SELECT * FROM Ponies WHERE FirstName='Pinkie' OR FirstName='Photo'

The result-set will look like this:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville
3 Finish Photo Biba Boutique Canterlot



Combining AND & OR

You can also combine AND and OR (use parenthesis to form complex expressions). Now we want to select only the ponies with the last name equal to "Pie" AND the first name equal to "Pinkie" OR to "Photo":

We use the following SELECT statement:

Spike: Please SELECT * FROM Ponies WHERE LastName='Pie' AND (FirstName='Pinkie' OR FirstName='Photo')

The clause LastName='Pie' will match both Inkie and Pinkie Pie, FirstName='Pinkie' will disregard Inkie and only match Pinkie, FirstName='Photo' will not match Photo Finish since clauses outside the parenthesis will take precedence over clauses inside the parenthesis and she is not matched in the first clause.

The result-set will look like this:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville





PQL Distinct PQL Order By

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.