Reputation: 23
If I have two conditions in a where statement that is in two different tables, is it required to make a join between them?
like:
select *
from customer, order
where customer = 'john'
and order = 'car'
Does it require them to have a join statement because I have two tables in from ?
Upvotes: 1
Views: 52
Reputation: 1269503
Let me assume that you intend:
select *
from customer c cross join
orders o
where c.customer = 'john' and o.order = 'car';
This is fine. I might expect that the orders
table would have a "customer id" of some sort. But if you want all "john"s cross with all "car"s, then the query does what you intend.
Some people would write this as an inner join:
select *
from customer c join
orders o
on c.customer = 'john' and o.order = 'car';
I'm fairy neutral -- except I strongly encourage you to spell out cross join
rather than using a comma.
Upvotes: 1
Reputation: 172
Yes you absolutely need to join those two tables to get the results you are looking for.
Upvotes: 0