Is dit de snelste manier?

Pagina: 1
Acties:

  • mark_gl
  • Registratie: September 2001
  • Laatst online: 23:18
Kan onderstaande code sneller met een inner join? Zo ja hoe? heb er nog nooit mee gewerkt misschien kan iemand mij een duwte in de rug geven?

cmdTemp.CommandText = "SELECT * FROM " & CONST_ONDERWERP_tabel & " WHERE parent='' order by volgorde,titel"
cmdTemp.CommandType = 1
set cmdTemp.ActiveConnection = DB
RS_root.Open cmdTemp, , 0, 1

while not (RS_root.eof or RS_root.bof)
response.write RS_root("code") & RS_root("titel")

cmdTemp.CommandText = "SELECT * FROM " & CONST_pagina_tabel & " WHERE onderwerp='" & RS_root("code") & "' order by volgorde, titel"
cmdTemp.CommandType = 1
set cmdTemp.ActiveConnection = DB
RS4.Open cmdTemp, , 0, 1

if not (RS4.eof or RS4.bof) then
response.write RS4("code") & RS4("titel")
RS4.movenext
end if
RS4.close
RS_root.movenext
wend
RS_root.close

  • Onno
  • Registratie: Juni 1999
  • Niet online
Probeer eens zoiets:
code:
1
2
"SELECT * FROM " & CONST_ONDERWERP_tabel & "a, " & CONST_pagina_tabel & "b
  WHERE a.parent='' AND b.onderwerp = a.code ORDER BY a.volgorde,a.titel,b.volgorde,b.titel"

  • mark_gl
  • Registratie: September 2001
  • Laatst online: 23:18
Deze join werkt nog niet helemaal goed ik heb nu dit


cmdTemp.CommandText = "SELECT * FROM " & CONST_ONDERWERP_tabel & ", " & CONST_pagina_tabel & " WHERE (" & CONST_ONDERWERP_tabel & ".parent ='') AND (" & CONST_pagina_tabel & ".onderwerp = " & CONST_ONDERWERP_tabel & ".code) ORDER BY " & CONST_ONDERWERP_tabel & ".volgorde"

Nu drukt ie ook nog onderwerpen af die bij parent wel iets hebben staan ookal staat er parent=''

  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

Inner join:

select * from <TABLE>, <TABLE2> where <TABLE>.key = <TABLE2>.key_fromtable2

of

select * from <TABLE> inner join <TABLE2> on <TABLE>.key = <TABLE2>.key_fromtable2

Meer info:
http://sqlcourse2.com/joins.html

Programmer - an organism that turns coffee into software.


  • mark_gl
  • Registratie: September 2001
  • Laatst online: 23:18
Hier een betere en uitgebreidere uitleg:

-Algemeen (onderwerp)
-Algemeen (pagina)
-Alvcxvcn1
-Alvcxvvcen
-Algemeevcxcvvn
-Algevxvxen

Ik voer nu deze inner join uit
SELECT " & CONST_ONDERWERP_tabel & ".code as code, " & CONST_ONDERWERP_tabel & ".zichtbaar as zichtbaar, " & CONST_ONDERWERP_tabel & ".titel as titel FROM " & CONST_ONDERWERP_tabel & " INNER JOIN " & CONST_pagina_tabel & " ON " & CONST_ONDERWERP_tabel & ".code = " & CONST_pagina_tabel & ".onderwerp AND " & CONST_ONDERWERP_tabel & ".parent = '' ORDER BY " & CONST_ONDERWERP_tabel & ".volgorde


Nu krijg ik dat ie sommige onderwerpen met meerdere pagina;s afdrukt ookal staat er bij parent iets (ik test wel parent='') hoe kan dit, is de join verkeerd?