If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Joining Table problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-14-04, 05:12
zakyk zakyk is offline
Registered User
 
Join Date: Mar 2003
Posts: 32
Question Joining Table problem

i have problem for get result from joining two table. better i show

tbl.name
name
a
b
c

tbl.cat
name | reg_cat
c 101
a 100
b 100
c 100

result

i make it search condition where name in tbl.cat doesn't have reg_cat = 101
then the result show

sql = "SELECT tbl.name.*,tbl.cat.* " &_
"FROM tbl.cat LEFT JOIN tbl.name ON tbl.name.name =tbl.cat.name WHERE tbl.cat. reg_cat <> '101'

name |
a
b
c

how can i get result just like this

name |
a
b

cause c is already have that record. any idea ?

tq
Reply With Quote
  #2 (permalink)  
Old 05-14-04, 05:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
left join in the other direction

condition in the ON, not WHERE

then check for null, which indicates an unmatched row
Code:
select tbl.name.*
     , tbl.cat.* 
  from tbl.name 
left outer
  join tbl.cat 
    on tbl.name.name 
     = tbl.cat.name 
   and tbl.cat.reg_cat = '101'
 where tbl.cat.name is null
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-16-04, 20:56
zakyk zakyk is offline
Registered User
 
Join Date: Mar 2003
Posts: 32
thanks r937 its works!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On