[thelist] mySQL query

john at johnallsopp.co.uk john at johnallsopp.co.uk
Wed Feb 23 04:20:35 CST 2005


> [snip]
> SELECT IT_D_id, IT_D_des, IT_D_wp, IT_D_wn, IT_D_s
> FROM `IT_D` id, `CAT` ca
> WHERE id.CA_id1 = ca.CA_id
> and ca.CAT_des='Chemical'
> order by IT_D_id desc limit 0,100
>
> SELECT IT_D_id, IT_D_des, IT_D_wp, IT_D_wn, IT_D_s
> FROM `IT_D` id, `CAT` ca, `CAT` ca2
> WHERE id.CAT_id1 = ca.CAT_id
> and id.CAT_id2 = ca2.CAT_id
> and (ca.CAT_des='Chemical' or ca2.CAT_des='Chemical')
> order by IT_D_id desc limit 0,100
> [/snip]
>
> Try
>
> SELECT IT_D_id, IT_D_des, IT_D_wp, IT_D_wn, IT_D_s
> FROM `IT_D` id LEFT OUTER JOIN `CAT` ca
> ON (id.CAT_id1 = ca.CAT_id)
> LEFT OUTER JOIN `CAT` ca2
> ON (id.CAT_id2 = ca2.CAT_id)
> WHERE ca.CAT_des='Chemical'
> order by IT_D_id desc limit 0,100
>
> This is a little hard to accomplish via e-mail without table
> descriptions and clearer column descriptors.

Many thanks, that worked. My book, Kofler, is a little light on such
things, and certainly isn't clear about all that.

It says 'OUTER' is optional and doesn't change anything. That appears
to be the case.

Cheers
J


More information about the thelist mailing list