[MySQL] Kom even niet uit de join

Pagina: 1
Acties:
  • 64 views sinds 30-01-2008

  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

Topicstarter
Ik heb twee tabellen
table1:
tbl1_id (int)
parent_id (int)

en table2:
tbl2_id
tbl1_id

Nu wil ik deze tabellen koppelen en alle data uit table1 halen en als er data in table2 staat erbij halen.
code:
1
2
3
4
5
6
7
8
  select
      table1.tbl1_id, tbl2_id
   form 
      table1
   left join 
      table2
   on 
     table1.tbl1_id= table2.tbl1_id


Dit gaat goed, nu wil ik een restrictie op tbl1_id = 313 of parent_id = 313

code:
1
2
3
4
5
6
7
8
9
10
11
  select
      table1.tbl1_id, tbl2_id
   form 
      table1
   left join 
      table2
   on 
     table1.tbl1_id= table2.tbl1_id
   where 
     table1.tbl1_id = 313 OR   // ALLE ID's die 313 hebben en in beide tabellen staan
     (parent_id = 313 and tbl2_id.tbl2.id is NULL)   // ALLE ITEMS Waarvan parent 313 is en alleen in table 1 staan.

Comments staan natuurlijk niet in de echte query.

Dit werkt niet... ik krijg alleen het gedeelte van deel 1 terug
Hoe kan ik dit wel oplossen...?

Programmer - an organism that turns coffee into software.


  • dusty
  • Registratie: Mei 2000
  • Laatst online: 21-02 00:06

dusty

Celebrate Life!

Als P&W meubilair weet jij als geen ander hoe je een goeie titel moet maken.

Back In Black!
"Je moet haar alleen aan de ketting leggen" - MueR


Dit topic is gesloten.