Reply to Re: MYSQL select question

Your name:

Reply:


Posted by Geoff May on 05/23/05 19:05

Dave wrote:
> Thanks Geoff,
>
> Did you mean:
> SELECT table_1.ID, table_1.NAME if(table_1.ID = table_2.ID, table_2.FLAG, 0)
> AS MY_FLAG
> FROM table_1, table_2
> WHERE table_1.ID LIKE '1000%' and table_1.ID = table_2.ID
> ORDER BY table_1.ID;
>
> If so this works but won't return the row:
> 10003 10002 name 0
>
> As the query is restricted by matching ID cols in both tables.

Then you need to use the JOIN, something like this:

SELECT table_1.ID, table_1.NAME, if(table_1.ID = table_2.ID,
table_2.FLAG, 0)
FROM table_1
left left join table_2 on (table_1.ID = table_2.ID)
where table_1.ID LIKE '1000%'
ORDER BY table_1.ID;

MfG

Geoff.

--
Unofficial F1 Database: http://glibs.ssmmdd.co.uk/
Update: 22nd May, 2005
USENET Email address is a spam trap, send Emails to address in the DB

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация