• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Urgent Oracle SQL Question (INNER JOIN)

Platypus

Ducklike
Joined
Dec 10, 2007
Messages
9,144
Likes received
627
Thanks received
182
Location
In the pub
Hi folks,

I have two tables, one containing detail records and one containing header records. The common columns are let's say CODE and CLIENT.

What I want to do is to select info from the detail records but join to the header record, like this:

SELECT
A.CODE, A.CLIENT, A.NAME,
B.DATE, B.AMOUNT
FROM HEADER A
INNER JOIN DETAIL B something

The pseudo-code for "something" is

FOR RECORDS WHERE A.CLIENT = B.CLIENT AND A.CODE = B.CODE

I think I can do it like this:

INNER JOIN ON A.CLIENT = B.CLIENT AND A.CODE = B.CODE

or

INNER JOIN ON A.CLIENT||A.CODE = B.CLIENT||B.CODE

Or would this do the same / be better ?

USING (CLIENT, CODE)

I don't have access to the target system, so I'm giving the local oppo instructions by email. It would be excellent if what I told him worked!

Thanks in advance!!
 
Select
A.code, A.client, A.name,
B.date, B.amount
From Header A
Inner Join Detail B
on
A.client = B.client
And A.code = B.code
 
Select
A.code, A.client, A.name,
B.date, B.amount
From Header A
Inner Join Detail B
on
A.client = B.client
And A.code = B.code

Many thanks!

What's the approved CUK way of sending free beers in gratitude?
 
Why not

Code:
SELECT a.code
,      a.client
,      a.name
,      b.date
,      b.amount
from   header a
,      detail b
where  a.client = b.client
and    a.code   = b.code
?

Oh - and "date" is a really bad name for a column, since it's a reserved word.
 
Why not

Code:
SELECT a.code
,      a.client
,      a.name
,      b.date
,      b.amount
from   header a
,      detail b
where  a.client = b.client
and    a.code   = b.code
?

Oh - and "date" is a really bad name for a column, since it's a reserved word.

that would work fine too, technically no reason not to
Personally I'd say that good practice dictates otherwise though
 
I don't have access to the target system, so I'm giving the local oppo instructions by email. It would be excellent if what I told him worked!


Sure, we believe you. Cheating on a technical test, naughty.
 

Advertisers

Back
Top