在 oracle 中连接多个表 sql
Join Multiple tables in oracle sql
我是 SQL 的新手,想知道如何用 SQL 连接替换下面的代码。
我想列出所有基于p_id ='123'的信息。
select p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact
from product p, category c, seller s, buyer b
where p.p_id="123" and c.p_id="123" and s.p_id="123" and b.p_id="123";
Table已使用
产品Table
p_id
p_name
类别Table
p_id
c_id
c_name
卖家Table
p_id
s_id
s_name
s_contact
买家Table
p_id
b_id
b_name
b_contact
谢谢
这是使用连接的查询:
select p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact
from product p
join buyer b on p.p_id = b.p_id and <second condition>
join category c on p.p_id = c.p_id
join seller s on c.p_id = s.p_id
where p.p_id="123" ;
尝试按照以下条件加入所有 table:
SELECT p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact
FROM product p INNER JOIN category c
ON p.p_id = c.p_id
INNER JOIN seller s
ON p.p_id = s.p_id
INNER JOIN buyer b
ON p.p_id = b.p_id
WHERE p.p_id='123';
我是 SQL 的新手,想知道如何用 SQL 连接替换下面的代码。
我想列出所有基于p_id ='123'的信息。
select p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact
from product p, category c, seller s, buyer b
where p.p_id="123" and c.p_id="123" and s.p_id="123" and b.p_id="123";
Table已使用
产品Table
p_id
p_name
类别Table
p_id
c_id
c_name
卖家Table
p_id
s_id
s_name
s_contact
买家Table
p_id
b_id
b_name
b_contact
谢谢
这是使用连接的查询:
select p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact
from product p
join buyer b on p.p_id = b.p_id and <second condition>
join category c on p.p_id = c.p_id
join seller s on c.p_id = s.p_id
where p.p_id="123" ;
尝试按照以下条件加入所有 table:
SELECT p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact
FROM product p INNER JOIN category c
ON p.p_id = c.p_id
INNER JOIN seller s
ON p.p_id = s.p_id
INNER JOIN buyer b
ON p.p_id = b.p_id
WHERE p.p_id='123';