-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProva_Views (Parte SQL)
More file actions
36 lines (28 loc) · 1.17 KB
/
Prova_Views (Parte SQL)
File metadata and controls
36 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Create table produtos (nome varchar(30),
preco int,
descricao varchar(50),
categoria int,
id_produto int);
Create table Usuario (nome varchar(30),
email varchar(50),
id_usuario int);
Create table carrinho (id_relacional int AUTO_INCREMENT primary key, /*transforma em AUTO INCREMENT dps */
id_usuario int,
id_produto int);
insert into produtos (nome, preco, descricao, categoria, id_produto)
values ('agenda', 5, 'agenda', 1, 3),
('pvc', 12, 'tubo', 2, 4),
('martelo', 30, 'martelo', 2, 5);
insert into Usuario (nome, email, id_usuario)
values('lucas', 'abc@gmail.com', 1),
('gabriel', 'pei@gmail.com', 2),
('juquinha', 'hiu@gmail.com', 3);
insert into carrinho(id_usuario, id_produto)
values(1, 1),
(1, 2),
(1, 3),
(2, 1),
(2, 2);
select carrinho.id_usuario, carrinho.id_produto, produtos.nome, produtos.categoria
from produtos
right join carrinho on produtos.id_produto = carrinho.id_produto