Created
June 1, 2024 21:12
-
-
Save Semior001/7f45e81d9207e1206fe53a3508a2a2f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id | price | name | |
---|---|---|---|
0 | 12345 | abacaba | |
0 | 12345 | cabaaba | |
1 | 54321 | wtf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table 'orders' ( | |
id integer primary key autoincrement, | |
customer_id int not null | |
); | |
create table 'prices' ( | |
id integer primary key autoincrement, | |
price int not null | |
); | |
create table 'items' ( | |
id integer primary key autoincrement, | |
order_id int not null, | |
name text not null default '', | |
price_id int not null, | |
constraint fk_order_id foreign key (order_id) references orders(id), | |
constraint fk_price_id foreign key (price_id) references prices(id) | |
); | |
insert into prices (id, price) values (0, 12345); | |
insert into prices (id, price) values (1, 54321); | |
insert into orders (id, customer_id) values (0, 0); | |
insert into orders (id, customer_id) values (1, 0); | |
insert into orders (id, customer_id) values (2, 1); | |
insert into orders (id, customer_id) values (3, 1); | |
insert into items (id, order_id, name, price_id) values (0, 0, 'abacaba', 0); | |
insert into items (id, order_id, name, price_id) values (1, 0, 'cabaaba', 0); | |
insert into items (id, order_id, name, price_id) values (2, 1, 'wtf', 1); | |
insert into items (id, order_id, name, price_id) values (3, 2, 'not shown', 1); | |
select orders.id, prices.price, items.name from items | |
join prices on items.price_id = prices.id | |
join orders on orders.id = items.order_id | |
where orders.customer_id = ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment