Ich habe Tabelle foo
mit Säulen:Auswahl mehrmals gleiche Fremdschlüssel in SQL
fid, lat, long
1, 0.1, 0.11
2, 0.2, 0.22
3, 0.3, 0.33
4, 0.4, 0.44
und Tabelle bar
:
bid, f1, f2, f3
1, 1, 2, 3
2, 4, 3, 1
ich die lat
, long
von f1
erhalten möchten, f2
, f3
für jeden Eintrag von bar
Tabelle.
Bisher habe ich die Abfrage erstellt:
select
b.bid,
f1.lat, f1.long,
f2.lat, f2.long,
f3.lat, f3.long
from
bar as b,
foo as f1,
foo as f2,
foo as f3
where
b.f1=f1.fid and
b.f2=f2.fid and
b.f3=f3.fid;
bid, lat, long, lat, "long", "lat", "long"
1, 0.1, 0.11, 0.2, 0.22, 0.3, 0.33
2, 0.4, 0.44, 0.3, 0.33, 0.1, 0.11
Die foo.fid
und bar.bid
sind Primärschlüssel. Außerdem kann ich jeden benötigten Index zu den Tabellen hinzufügen.
Gibt es eine schnellere effizientere Abfrage, um das gleiche Ergebnis zu erhalten?
Haben Sie Indizes/Schlüssel? – jarlh
Sorry @jarlh, ich habe es vergessen. Ich habe die Frage bearbeitet – ztik