This isn't a PHP question at all. It's a MySQL question. However, answers are below, with forwards to the appropriate lists for archiving purposes. On Mon, Jun 2, 2008 at 9:19 PM, LKSunny <ad@xxxxxxxx> wrote: > two table, tablea and tableb > tablea > uid, col1, col2, col3 > 1, xx, xx, xx > 2, xx, xx, xx > 3, xx, xx, xx > tableb > id, uid, col1, firstdata > 1, 1, xx, 1 > 2, 2, xx, 0 > 3, 2, xx, 0 > 4, 1, xx, 0 > > i want query tablea, and join tableb, uid is associate, ok "LEFT JOIN > `tableb` b ON a.uid = b.uid", and than i want tableb firstdata=1 or tableb > no associate uid "b.firstdata=1 OR b.uid IS NULL", by the time all ok, but i > want add one case, if tableb firstdata all is 0, result one row, like b.uid > IS NULL, i don't know how to > > i want result is all tablea data no double, tableb one case firstdata is 1 > (one uid in tableb just one row possible is firstdata=1), or no row in > tableb, or all firstdata = 0 > > Thank You Very Much !! > > This query can't > SELECT a.*, b.* FROM `tablea` a LEFT JOIN `tableb` b ON a.uid = b.uid WHERE > (b.firstdata=1 OR b.firstdata=0 OR b.uid IS NULL) Okay, I had a difficult time understanding what it is you need, but hopefully got enough from your message to be able to help you out. What I think you may be looking for is something like this: SELECT * FROM tableb WHERE firstdata='1' AND id IN (SELECT DISTINCT id FROM tablea ORDER BY id ASC); That will select only unique `id` columns from `tablea` and select only the rows from `tableb` where the `id` columns match and `firstdata` is set to '1'. You can then modify that query as needed. -- </Daniel P. Brown> Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php