Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange LEFT JOIN

Status
Not open for further replies.

bobo123

Programmer
Oct 4, 2002
30
Hi all !

I tried a command (from phpMyAdmin):
SELECT * FROM dttips t left join dtbets b on t.datum=b.datum and t.userid=b.userid where t.tip not like '0000%' and t.datum like '2004%' and (b.sazka='000' or isnull(b.sazka)) and t.userid='pepa'

I've got 30 records in table t, 18 records in table b (with right key), but always get only 18 records !!! I would expect 30 lines (with LEFT JOIN) - 18 regular and 12 with 'b' table NULL 'tail'!!!
where is a problem ??
Any ideas ?
Thanks a lot !!
bobo
 
can you give us some sample data from the tables?

also try removing the where clause from your statement real quick and see what you get, maybe the where clause, and not the left join is what is limiting your query...

you where clause asks that table b.sazka is either null, or equals 000. Is all data in b.sazka 000?

***************************************
J. Jacobs
 
try it like this --
Code:
select * 
  from dttips t 
left outer
  join dtbets b 
    on t.datum = b.datum 
   and t.userid = b.userid 
   and b.sazka = '000'
 where t.tip not like '0000%' 
   and t.datum like '2004%' 
   and t.userid = 'pepa'

rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top