SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table orders_1 (user_id int, order_id int, create_time datetime); insert into orders_1 values (1, 5, '2018-05-04 02:26:03.808'), (1, 6, '2021-01-01 02:26:03.821'), (1, 12, '2021-12-12 02:26:03.814'); create table orders_2 (user_id int, order_id int, create_time datetime); insert into orders_2 values (6, 7, '2020-06-04 02:26:03.808'), (1, 5, '2021-01-01 02:26:03.821'), (3, 4, '2021-12-12 02:26:03.814'); select a.user_id, a.order_id, a.create_time as "create_time_1", b.create_time as "create_time_2" from orders_1 a join orders_2 b on a.user_id = b.user_id and a.order_id = b.order_id create table orders_3 (user_id int, order_id int, create_time datetime); insert into orders_3 values (77, 2, '2015-09-15 02:26:03.808'), (3, 4, '2018-04-15 02:26:03.814'); select a.user_id, a.order_id, a.create_time as "create_time_1", b.create_time as "create_time_2", c.create_time as "create_time_3" from orders_1 a join orders_2 b on a.user_id = b.user_id and a.order_id = b.order_id left join orders_3 c on a.user_id = c.user_id and a.order_id = c.order_Id

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear