View previous topic :: View next topic
|
Author |
Message |
kaustuv ch
New User
Joined: 19 Aug 2014 Posts: 1 Location: USA
|
|
|
|
Hi All
My first post in this forum and I apologize for starting with a question. I have tried researching on the below query but I could not find/get a solution. Any help is highly appreciated.
1)Generate SQL query that will provide records where account id matches, but if account id does not match, then check for match of cost center id, then check for match of company id
Table name:
Accounts Raw
Columns:
Account ID
Account Cost Center ID
Account Company ID
Table name:
Accounts Target
Columns:
Account ID
Account Cost Center ID
Account Company ID |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Hello and welcome to the Forum.
This sentence does not make much sense (to me):
kaustuv ch wrote: |
provide records where account id matches, but if account id does not match, then check for match of cost center id, then check for match of company id |
Consider:
1. Rephrasing the question.
2. Providing an example (or two).
3. Providing the query you have written so far. |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi,
if I understand your question correctly check if below query help you
Code: |
SELECT
A.Account ID ,
A.Account Cost Center ID ,
A.Account Company ID,
B.Account ID ,
B1.Account Cost Center ID ,
B2.Account Company ID,
FROM Accounts Raw A
LEFT OUTER JOIN
Accounts Target B
ON A.Account ID = B.Account ID
LEFT OUTER JOIN
Accounts Target B1
ON A.Account Cost Center ID= B1.Account Cost Center ID
LEFT OUTER JOIN
Accounts Target B2
ON A.Account Company ID = B2.Account Company ID |
in the result value for B, B1 and B2 will have null values if there is no matching row found.
But as marso mentioned your description doesn't make it clear to me as well
I would also suggest what Marso did already
I just thought of giving the query if it suits your requirement
Regards,
Chandan |
|
Back to top |
|
|
|