I have a study assignment and I’ve been banging my head in the wall for at least a day now.
I’m totally new to this and just learning the basics.
This is my assignment:
Use union to combine these queries:
- Select customers whose city and postalcode both appear in suppliers table.
- Select customers whose name is at most five characters shorter than the longest supplier name.
Northwind database in question.
This is what i tried:
select customername, customers.city, customers.postalcode
from customers join suppliers
on customers.city = suppliers.city and customers.PostalCode = suppliers.PostalCode
union
select customername, customers.city, customers.postalcode
from customers
where length(customername) <
(select max(length(suppliername))
from suppliers)
Problem is that last “where clause”.
I know that the longest suppliername has 38 characters:
(select max(length(suppliername))
from suppliers) =38 characters
But i don’t know how to query that “at most five characters shorter”.
I get correct result set by querying:
where length(customername) > 33
but obviously that’s not what is asked for.
Thank you for the help 🙂
Valtteri Kallas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.