Thread: UNION or UNION ALL

UNION or UNION ALL

From
Abdul Wahab Dahalan
Date:
I've 3 tables A,B,C <br />records in table A like: <br /><u>id          name</u><br />b1        abc <br />b2       
xyz<br />b3        rst <p>records in table B like: <br /><u>id        type</u><br />b1        logistics <br />b1       
importer<br />b2        logistics <br />b3        logistics <br />b3        exporter <p>records in table C like: <br
/><u>id       offer        title</u><br />b1        sell        car <br />b1        buy        car <br />b1       
sell       van <br />b2        sell        car <p>How shoul I do a query so that I can get a result like <br />(The
querywill be based on B.type ='logistics') <br /><u>id        name       offer</u><br />b1        abc        sell <br
/>b1       abc        buy <br />b1        abc        sell <br />b2        xyz        sell <br />b3       
rst           -- <p>Any help very much appricated 

Re: UNION or UNION ALL

From
Tomasz Myrta
Date:
Abdul Wahab Dahalan wrote:> I've 3 tables A,B,C> records in table A like:> id          name> b1        abc> b2
xyz>b3        rst>> records in table B like:> id        type> b1        logistics> b1        importer> b2
logistics>b3        logistics> b3        exporter>> records in table C like:> id        offer        title> b1
sell       car> b1        buy        car> b1        sell        van> b2        sell        car>> How shoul I do a query
sothat I can get a result like> (The query will be based on B.type ='logistics')> id        name       offer> b1
abc       sell> b1        abc        buy> b1        abc        sell> b2        xyz        sell> b3        rst
-->> Any help very much appricated
 
select  id,  name,  offer
from  A  join B using (_id)  left join C using (_id)
where type='logistics';

As you see, you don't need any UNION ;-)

BTW - please - turn off HTML format in your mail client.

Regards,
Tomasz Myrta