Skip to content

SQL Join Type Examples

SQL Join Type Example 1

SELECT * FROM BikeStores.sales.orders [orders]
inner join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
order by customer_id;

SQL Join Type Example 2

SELECT customer_id,COUNT(item.order_id) [total order] FROM BikeStores.sales.orders [orders]
inner join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
group by customer_id
order by customer_id;

SQL Join Type Example 3

SELECT customers.first_name,COUNT(item.order_id) [total order] FROM BikeStores.sales.orders [orders]
inner join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
inner join BikeStores.sales.customers as customers
On customers.customer_id = orders.customer_id
group by first_name
order by [total order] desc;
sql join table-3
sql join table-3

SQL Join Type Example 4

SELECT first_name, last_name ,COUNT(item.order_id) [total order] FROM BikeStores.sales.orders [orders]
inner join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
inner join BikeStores.sales.customers as customers
On customers.customer_id = orders.customer_id
group by first_name,last_name
order by [total order] desc;

SQL Join Type Example 5

SELECT * FROM BikeStores.sales.orders [orders]
right join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
order by customer_id;

SELECT * FROM BikeStores.sales.orders [orders]
left join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
order by customer_id;

SELECT * FROM BikeStores.sales.orders [orders]
inner join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
order by customer_id;
sql join example
sql join example

SQL Join Type Example 6

SELECT * FROM BikeStores.sales.orders [orders]
right join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id and item.order_id = 120
order by customer_id;

SELECT * FROM BikeStores.sales.orders [orders]
left join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id and item.order_id = 120
order by item.order_id;

SELECT * FROM BikeStores.sales.orders [orders]
inner join BikeStores.sales.order_items as [item]
ON orders.order_id = item.order_id
order by customer_id;
sql join example
sql join example

To access the database: click

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: