如何从两个表中选择字段

时间:2011-07-01 07:20:25

标签: sql

我需要选择这些字段-----

user_id,
sales_vertical,
partner_id,
category,
sub_category,
stage_id,
exp_revenue,
action,
action_date,
title_action,
date_action,
details from opportunity_history table

tri_title,
tri_subtitle 
from res_partner table 
where res_partner.partner_id = opportunity_history.partner_id 
单个查询中的

。 我们怎么能这样做?

感谢Adil

6 个答案:

答案 0 :(得分:12)

为什么这么多的downvotes和没有评论?

尝试:

SELECT 
    oh.ser_id,
    oh.sales_vertical,
    oh.partner_id,
    oh.category,
    oh.sub_category,
    oh.stage_id,
    oh.exp_revenue,
    oh.action,
    oh.action_date,
    oh.title_action,
    oh.date_action,
    oh.details,

    rp.tri_title,
    rp.tri_subtitle

FROM opportunity_history AS oh
  INNER JOIN res_partner AS rp
    ON rp.partner_id = oh.partner_id 

答案 1 :(得分:3)

select user_id, sales_vertical, partner_id, category, sub_category, stage_id, exp_revenue, action, action_date,title_action,date_action,details, tri_title, tri_subtitle 

from opportunity_history, res_partner

where res_partner.partner_id =opportunity_history.partner_id 

答案 2 :(得分:1)

SELECT a.user_id, a.sales_vertical, a.partner_id, a.category, a.sub_category, 
a.stage_id, a.exp_revenue, a.action, a.action_date, a.title_action, a.date_action, 
a.details, b.tri_title, b.tri_subtitle FROM opportunity_history a, res_partner b 
WHERE b.partner_id =a.partner_id

答案 3 :(得分:1)

可能的解决方案(不是单一查询)

(SELECT user_id, sales_vertical, partner_id, category, sub_category, stage_id, exp_revenue, action_date, title_action, date_action, details FROM opportunity_history) UNION ALL (SELECT tri_title, tri_subtitle FROM res_partner WHERE res_partner.partner_id=opportunity_history.partner_id)

答案 4 :(得分:0)

检查这些:
- SELECT Data from multiple tables?(适用于任意数量的表格,而不仅仅是2个) - SQL select statement from 2 tables

答案 5 :(得分:0)

选择顶部(100)                          PRJ.tblAvoidance.Updated_By,PRJ.tblAvoidance.Updated_On 从PRJ.tblAvoidance内部联接                          PRJ.tblNDCProjects开启PRJ.tblAvoidance.Project_ID = PRJ.tblNDCProjects.ID