Here’re SQL queries that explain how to use AND and OR and both conditions in the WHERE clause.

The purpose of AND is for all conditions to satisfy. On the other hand, the OR is to get rows that have any one condition satisfied.
So limiting rows in SQL [asktom.oracle.com/] output can do it using the where clause with AND and OR. The AND and OR conditions examples here show you how to achieve it.
SQL AND condition
In the below query, you will get rows, from the INVOICES table, where the invoice date is > 12th JAN 2022 and the Total is less than $5[developer.salesforce.com]
Invoices table

SELECT
InvoiceDate,
BillingAddress,
BillingCity,
Total
FROM
invoices
WHERE
DATE(InvoiceDate) > '2022-01-12' AND Total < 5
ORDER BY
Total
SQL OR condition
The OR operator in the WHERE allows you to get rows that match any criteria. The below query pulls the rows BillingCity’s first letter of ‘p’ or ‘d.’
SELECT
InvoiceDate,
BillingAddress,
BillingCity,
Total
FROM
invoices
WHERE
BillingCity LIKE 'p%' OR BillingCity LIKE 'd%'
ORDER BY
Total
SQL AND and OR conditions
This query shows you to use both AND and OR. So that you can limit the rows in the output.
SELECT
InvoiceDate,
BillingAddress,
BillingCity,
Total
FROM
invoices
WHERE
Total > 1.98 AND BillingCity LIKE 'p%' OR
BillingCity LIKE 'd%'
ORDER BY
Total
Related
You must be logged in to post a comment.