|
Posted by Stefan Rybacki on 11/17/05 15:32
FatCoin wrote:
> Hi,
>
> 1. pic TABLE ROWs
> |id_pic |desc
> |1 |pic1.jpg
> |2 |pic2.jpg
> |3 |pic3.jpg
>
> 2. pic_desc TABLE ROWs
> |id_pic |lang |desc
> |1 |hr |desc 1 HR
> |2 |hr |desc 2 HR
> |2 |en |desc 2 EN
>
> My query (parametar 'lang'):
> SELECT pic.id_pic, pic.pic, pic_desc.desc
> FROM pic
> LEFT JOIN pic_desc ON pic.id_pic = pic_desc.id_pic
> WHERE pic.id_entry =1
> AND (
> pic_desc.lang = 'en'
> OR pic_desc.lang IS NULL
> )
Here you're filtering out your missing picture. See what happens
pic LEFT JOIN pic_desc ON ... gives you
|1 |pic1.jpg| hr
|2 |pic2.jpg| hr
|2 |pic2.jpg| en
|3 |pic3.jpg| null
Now you doing a where on this result (WHERE pic_desc.lang='en' OR pic_desc.lang IS NULL)
So the first row disappears in this filter.
What you have to do is to add the language filter to the ON clause.
SELECT pic.id_pic, pic.pic, pic_desc.desc
FROM pic
LEFT JOIN pic_desc ON pic.id_pic = pic_desc.id_pic AND pic_desc.lang='en'
WHERE pic.id_entry =1
Regards
Stefan
>...
> Thanx
Navigation:
[Reply to this message]
|