can I write this statement shorter?
Select S_name
from
Supplier
JOIN Nation ON Supplier.S_nationkey = Nation.N_nationkey
JOIN Region on Nation.n_regionkey = region.R_regionkey
Where
Region.r_name = 'AFRICA'
Union
Select C_name
from
Customer
JOIN Nation ON Customer.C_Nationkey = Nation.N_nationkey
JOIN Region on Nation.N_regionkey = Region.R_regionkey
Where
Region.R_name = 'AFRICA'
and I want to order my output by name, But i dont know why, cause I do have C_name and S_Name as Output?!
thanks
If you want all the data in the same column then you can place a SELECT around it and then do an ORDER BY.
Select S_name As Names
from Supplier
JOIN Nation
ON Supplier.S_nationkey = Nation.N_nationkey
JOIN Region
on Nation.n_regionkey = region.R_regionkey
Where Region.r_name = 'AFRICA'
Union
Select C_name As Names
from Customer
JOIN Nation
ON Customer.C_Nationkey = Nation.N_nationkey
JOIN Region
on Nation.N_regionkey = Region.R_regionkey
Where Region.R_name = 'AFRICA'
ORDER BY Names
If you don't need the data in the same column, then you could do it this way:
Select S_name, c.C_name
from Supplier
JOIN Nation
ON Supplier.S_nationkey = Nation.N_nationkey
JOIN Region
on Nation.n_regionkey = region.R_regionkey
JOIN Customer c
on Nation.N_nationkey = c.C_Nationkey
Where Region.r_name = 'AFRICA'
ORDER BY S_name, c.c_name
As for order by clause, try
ORDER BY 1
at the end of your query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With