[sql] order by linken naar andere tabel

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

  • Michali
  • Registratie: Juli 2002
  • Laatst online: 22-03 18:12
Stel je hebt deze twee tabellen

table 1
id
col
id_table2


table 2
id
col
order_by_this


Nu wil ik de gehele inhoud van table 1 ophalen en laten sorteren aan de hand van de kolom order_by_this in table 2. Die kan ik weer bereiken via id_table2.

Ik weet zeker dat dit in één query kan en het zal wel niet al te moeilijk zijn maar ik ben nu eenmaal (nog) niet zon ster in SQL en dus heb ik de vraag hoe dat er dan ongeveer uit moet komen te zien.

Noushka's Magnificent Dream | Unity


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Kijk eens naar het stukje over joins in de FAQ.

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

En daarmee is ie wel afgedaan denk ik zo :z

Professionele website nodig?


  • justmental
  • Registratie: April 2000
  • Niet online

justmental

my heart, the beat

Je zult vanuit beide tabellen moeten selecteren.
Je moet ze dus joinen.
code:
1
2
3
4
5
6
7
select t1.id
,      t1.col
,      t2.order_by_this
from   table1 t1
,      table2 t2
where  t1.id_table2 = t2.id
order by t2.order_by_this

Who is John Galt?


Dit topic is gesloten.