Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT FROM ? HOW 1

Status
Not open for further replies.

straatlang

Technical User
Apr 7, 2003
40
NL
I have two tables :

Articles

ID Name
123 AAA
456 BBB
789 CCC
888 DDD

Prices

ID Price
123 10
456 20
789 30
999 40

The query should result in a list where all information that is available
is visiable. SO infact in need to combine these two tabels.

ID Name Price
123 AAA 10
456 BBB 20
789 CCC 30
888 DDD
999 40

Does anyone knows if this possible with SQL.

 
Code:
select coalesce(a.id,p.id) as id, a.name, a.price
  from articles a full outer join prices p
    on a.id = p.id
 
Hi Swampboogie,

Nice to hear from you.

Actualy I am using MS-Access I have tried your SQl but if is given some errors do you also have a solution which I can use in MS-Access.

Thanks



 
Access, I see. Access does not support full outer joins nor coalesce.

Code:
select iif(aid is null,pid,aid) as id, name, price
  from (select a.id as aid, p.id as pid,a.name,p.price
          from articles a left outer join prices p
          on a.id = p.id 
        union
       select a.id, p.id,a.name,p.price
          from articles a right outer join prices p
          on a.id = p.id 
       ) dt

 
Dear Swampboogie,

Fantactic it works. I copy and past it into Access and the result is exactly what I needed.

Thanks again

Straatlang

 
>Actualy I am using MS-Access

Umm... this happens to be the PostgreSQL forum. Unless you are using Access as a front-end to PostgreSQL, I don't see why this was posted here. -------------------------------------------

My PostgreSQL FAQ --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top