Answer the question
In order to leave comments, you need to log in
How to make SQL query from multiple tables?
help to make request:
There are 2 tables: users, orders.
users: id, name, s_name, email
orders: product_name, product_id, user_id
Select: Name, S_name, email ('users') by user_id and matching product_id (orders)
Answer the question
In order to leave comments, you need to log in
You can use the WHERE ... EXISTS (SELECT ...)
select name, s_name, email
from users
where users.id = 1 and exists (
select 1 from orders where user_id = users.id and product_id = 2
);
select distinct name, s_name, email
from users
join orders on orders.user_id = users.id
where users.id = 1 and product_id = 2;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question