在Oracle SQL中联接多个表 [英] Join Multiple tables in oracle sql

查看:107
本文介绍了在Oracle SQL中联接多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SQL的新手,并且想知道如何用SQL连接替换下面的代码.

im new to SQL and want to know how to replace the below code with SQL joins.

我想基于p_id ='123'列出所有信息.

I want to list all information based on 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";

使用的表

产品表

p_id
p_name

类别表

p_id
c_id
c_name

卖方表

p_id
s_id
s_name
s_contact

买家表

p_id
b_id
b_name
b_contact

谢谢

推荐答案

这是使用join进行的查询:

This is the query using join:

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" ;

这篇关于在Oracle SQL中联接多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆