Saturday, 23 November 2019 16:51

Some SQL questions and answers

Written by 
Rate this item
(0 votes)

Following are some SQL questions and answers, you may require it.

 1. Display all information from the EMPLOYEES table 

SELECT * FROM employees 

2. Display company name and contact for all CUSTOMERS

SELECT CompanyName, phone FROM customers 

3. Display first name and last name for all EMPLOYEES as one column, label the column

“Name�

SELECT CONCAT(FirstName, " ", LastName) AS Name FROM employees

4. Display the name of all PRODUCTS in stock.

select ProductName from products 

where UnitsInStock>0 AND UnitsInStock IS NOT NULL 

5. Display the name of all PRODUCTS that cost $10 or less

SELECT ProductName FROM products WHERE UnitPrice<=10 

6. Display name of all EMPLOYEES hired after 1992 

SELECT CONCAT(FirstName, " ", LastName) AS Name FROM employees WHERE YEAR(HireDate) > 1992 

7. Display name of all PRODUCTS that cost between $10 and $20

SELECT ProductName FROM products WHERE UnitPrice BETWEEN 10 AND 20 

8. Display the name and phone # for CUSTOMERS that have no fax number listed

SELECT ContactName, Phone 

FROM customers 

WHERE Fax IS NULL

9. Display EMPLOYEE information for employees born in March, June or September

SELECT * FROM employees WHERE MONTH(BirthDate)=3 OR MONTH(BirthDate)=6 OR MONTH(BirthDate)=9

10. Display all EMPLOYEES that are involved with sales sorted alphabetically by their last

name.

SELECT * FROM employees WHERE Title like 'sales %' OR Title like '%sales%' OR Title like '%sales %' ORDER BY LastName 

11. Display the product name and supplier name for all products that cost less than $10 for

suppliers from the UK

SELECT products.ProductName,suppliers.CompanyName FROM products JOIN suppliers ON products.SupplierID = suppliers.SupplierID WHERE products.UnitPrice<10 AND suppliers.Country= 'UK'

12. Display the name(s) and product cost of the supplier with the most expensive product.

You may use multiple queries for this.

SELECT suppliers.CompanyName, products.UnitPrice AS ProductCost FROM suppliers JOIN products on suppliers.SupplierID=products.SupplierID WHERE UnitPrice IN ( SELECT MAX(UnitPrice) FROM products) 

Don't forget to like & share it. 

Connect with me if you want to learn - https://www.fiverr.com/mitsol

Read 2021 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.