0% found this document useful (0 votes)
24 views3 pages

Training Query1 Select Operators

select

Uploaded by

anshkanch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Training Query1 Select Operators

select

Uploaded by

anshkanch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

(1) select all columns from Customers table

SELECT * FROM Customers;

(2) select all columns from the customers table with last_name 'Doe' (= Operator)

SELECT * FROM Customers WHERE last_name = 'Doe';

(3) select all columns from Customers table with age greater than 25 (> operator)

SELECT * FROM Customers WHERE age > 25;

(4) select all columns from Customers table with last_name 'Doe' and country 'USA' (and operator)

SELECT * FROM Customers WHERE last_name = 'Doe' AND country = 'USA';


(5) select the first_name and last_name of all customers (selecting only few attributes)

-- who live in 'USA' and have the last name 'Doe'

SELECT first_name, last_name FROM Customers WHERE country = 'USA' AND last_name = 'Doe';

(6) select customers who don't live in the USA (Not Operator)

SELECT first_name, last_name FROM Customers WHERE NOT country = 'USA';

(7) select customers who live in either USA or UK and whose age is less than 26 (combination of
operators)

SELECT * FROM Customers WHERE (country = 'USA' OR country = 'UK') AND age < 26;

(8) exclude customers who are from the USA and have 'Doe' as their last name (use of NOT operator)

SELECT * FROM customers WHERE NOT country = 'USA' AND NOT last_name = 'Doe';

(9) select rows if the country is either USA or UK

SELECT first_name, country FROM Customers WHERE country IN ('USA', 'UK');

(10) select rows where country is not UK or UAE

SELECT first_name, country FROM Customers WHERE country NOT IN ('UK', 'UAE');

(11) select rows where the age is between 25 and 30

SELECT * FROM Customers WHERE age BETWEEN 25 AND 30;

(12) selects all customers with a CustomerName starting with "a":

SELECT * FROM Customers

WHERE first_Name LIKE 'a%';

(13) SQL statement selects all customers with a CustomerName ending with "a":

SELECT * FROM Customers

WHERE first_Name LIKE '%a';

(14) SQL statement selects all customers with a CustomerName that have "or" in any position:
SELECT * FROM Customers

WHERE first_Name LIKE '%or%';

(15) selects all customers with a CustomerName that have "r" in the second position

SELECT * FROM Customers

WHERE first_Name LIKE '_r%';

(16) selects all customers with a CustomerName that starts with "a" and are at least 3 characters in
length:

SELECT * FROM Customers

WHERE first_Name LIKE 'a__%';

(17) selects all customers with a first_Name that does NOT start with "a":

SELECT * FROM Customers

WHERE first_Name NOT LIKE 'a%';

(18) statement selects all customers with first name containing the pattern "es":

SELECT * FROM Customers

WHERE first_name LIKE '%es%';

(19) selects all customers with a first name starting with "a", "b", or "c":

SELECT * FROM Customers

WHERE first_name LIKE '[a-c]%';

You might also like