SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table users (id int, name varchar(64), s_name varchar(64), email varchar(255)); insert into users values (1, 'User1', 'S_User1', 'user1@mail.com'), (2, 'User2', 'S_User2', 'user2@mail.com'), (3, 'User3', 'S_User3', 'user3@mail.com'); create table orders (product_name varchar(64), product_id int, user_id int); insert into orders values ('Product1', 1, 1), ('Product2', 2, 1), ('Product3', 3, 1); 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;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear