How to select fields from two tables

I need to select these fields -----

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 

and

 tri_title, tri_subtitle from res_partner table where res_partner.partner_id = opportunity_history.partner_id 

in one request. How can we do this?

Thanks Adil

+4
source share
5 answers

Why are there so many downvotes and no comments?

Try:

 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 
+11
source
 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 
+3
source
 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 
+1
source

Possible solution (not in one request)

(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)

+1
source

Check them out:
- SELECT data from multiple tables? (for any number of tables, not just 2)
- SQL select statement from 2 tables

0
source

All Articles