5

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 a single query. how can we do that?

Thanks Adil

Caspar Kleijne
  • 21,552
  • 13
  • 72
  • 102
Adil
  • 79
  • 1
  • 1
  • 2
  • Can you try to format your question better and give a bit more background. The question's current state makes it hard for us to see what you want to do really. – Mikael Östberg Jul 01 '11 at 07:24
  • possible duplicate of [Simple SQL Select from 2 Tables (What is a Join?)](http://stackoverflow.com/questions/11040587/simple-sql-select-from-2-tables-what-is-a-join) – FoamyGuy Jun 15 '12 at 21:23

6 Answers6

14

Why so many downvotes and no comments?

Try with:

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 
ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
  • So many downvotes and no comments because it's obvious that someone hasn't even tried to figure out the answer. Joins would be like day 2 in some "SQL in 7 days" book. (Just checked...they're "day 6" in the 21 days book. [Literally.](http://web.ing.puc.cl/~jlortiz/Teach_Yourself_SQL_in_21_days_FULL.pdf)) – cHao Jul 01 '11 at 09:22
  • 4
    but then, they should tell him that too - I don't like lazy people either, but I think that they might be helped to get corrected :) – Tudor Constantin Jul 01 '11 at 09:29
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 
love Computer science
  • 1,824
  • 4
  • 20
  • 39
2

Possible solution (not in single query)

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

kyrylo
  • 1,691
  • 1
  • 15
  • 22
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
Balanivash
  • 6,709
  • 9
  • 32
  • 48
0

SELECT TOP (100) PRJ.tblAvoidance.Av_ID, PRJ.tblAvoidance.Project_ID, PRJ.tblNDCProjects.Title, PRJ.tblAvoidance.Activity_Year, PRJ.tblAvoidance.CO2, PRJ.tblAvoidance.CH4, PRJ.tblAvoidance.N2O, PRJ.tblAvoidance.Updated_By, PRJ.tblAvoidance.Updated_On FROM PRJ.tblAvoidance INNER JOIN PRJ.tblNDCProjects ON PRJ.tblAvoidance.Project_ID = PRJ.tblNDCProjects.ID

Noor
  • 1
  • 3
    Welcome to StackOverflow! Please elaborate your answer adding some description of what it does and why is it better than other answers here. Also, please consult this [article](https://stackoverflow.com/help/formatting) for formatting help. – Denis Sheremet Dec 16 '19 at 12:15
0

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

Community
  • 1
  • 1
athspk
  • 6,722
  • 7
  • 37
  • 51