SQL Refresher # 02

Problem : Show number of customers in each city

Solution :
SELECT count(*) , City from customers
GROUP BY city
Problem: Show only those cities with there customers counts where no of customers greater than 1

Solution :
SELECT count(*) , City from customers
GROUP BY city
HAVING count(*) > 1
Problem: Only select customers who made their orders
Solution #1
SELECT customers.first_name , customers.last_name
from Orders, customers
where orders.customer_id = customers.id
Solution #2
SELECT CONCAT(customers.first_name ,' ', customers.last_name) as CustomerName
from Orders, customers
where orders.customer_id = customers.id

Comments