First thanx to all those how answered:
Benjamuin Pflugmann
Gerald Clark.
hcir
Dicky Purnomo

Original posting is below.

The best answer came from Benjamin and he also gave a good 
explanation why:
"Because it relates to the times table and you want to see
the users regardless, you have to put it in the ON clause, too:

SELECT u.id, u.surname, t.*
FROM   users u
LEFT OUTER JOIN times t ON u.id = t.id AND t.date = [current_date]
WHERE  u.id = 22

In other words, whenever you can say "I want to see the content of 
the left table (here: user) even if there is no match in the right one 
(here: times)", you have to put the condition in question into the ON 
clause of the  LEFT JOIN instead of the WHERE clause (which would 
restrict the end result)."

I got this from my tables:

22|Price|NULL|NULL| NULL|NULL|NULL|NULL|NULL| NULL|NULL |

Which is exactly what I want - I can use the surname,id to reply to the 
user. I also know that they haven't used the system that day - which is 
why, for those that asked, you don't see date information, because 
that user hasn't got an entry for that day.

Anyway I mighty thanx to Benjamin for that cos I learnt something 
today.
Dp.

------------- Original posting -------------

I want to select data from 2 tables conditionally. 1 table has users, the
other times relating to the users. I want to create a query that will
select the user from the users table and if they have any time data
against them (for that day) return that also. If there is not data for
that day only the user data should be returned.

If I do:
SELECT u.id,u.surname,t.* 
FROM users u LEFT OUTER JOIN times t
ON (u.id =t.id) 
WHERE u.id = 22;

I get:
22|Price|NULL|NULL| NULL| NULL| NULL| NULL| NULL| NULL  

Which I could work with but once I add "AND t.date = (current_date) 
I get 0 records returned and I need the users.id an users.surname.

Can anyone think of a way round this?
~~
Dermot Paikkos * [EMAIL PROTECTED]
Network Administrator @ Science Photo Library
Phone: 0207 432 1100 * Fax: 0207 286 8668


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to