Supportnet Computer
Planet of Tech

Supportnet / Forum / Datenbanken

SQL abfragen verknüpfen





Frage

Servus Habe folgende 2 Abfragen: select obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value from obj_int, obj_systext where obj_int.obj_type=-300 and obj_systext.obj_type=-300 and obj_int.obj_id=obj_systext.obj_id group by obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value select obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value from obj_int, obj_systext where obj_int.obj_type=-300 and obj_systext.obj_type=42 and obj_int.obj_id=obj_systext.obj_id group by obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value das resultat ist folgendes: 1 Abfrage) obj_type obj_id int_value text_value -300 0 1 Damian -300 1 1 Fest -300 2 2 Homepage -300 3 2 Stadtfest -300 4 0 zürifest 2 abfrage: obj_type obj_id int_value text_value -300 0 1 Wil -300 1 1 Winterthur -300 2 2 Freidorf Ich möchte eine Abfrage die mir folgendes ausgibt: -300 0 1 Damian winterthur -300 1 1 Fest winterthur -300 2 2 Homepage freidorf -300 3 2 Stadtfest freidorf -300 4 0 zürifest wil Problempunkt: die ortschaften und die Namen (damian...) sind in der gleichen tabelle angelegt, sie werden durch die obj_id (0,1,2) in einer zweiten Tabelle zugewiesen also z.b. -300 (namen)hat den int_value 1, also ist der ort winterthur. Kann mir jemand helfen dies in einer abfrage zu machen? erwünschtes resultat siehe oben gruss und dank kirtas

Antwort 1 von El Bobbele

Moin kirtas!

Probiere das mal aus:

SELECT temp.obj_type, temp2.obj_int, temp.int_value, temp.text_value + ' ' + temp2.text_value AS text_value FROM (SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
FROM obj_int, obj_systext
WHERE obj_int.obj_type=-300
AND obj_systext.obj_type=-300
AND obj_int.obj_id=obj_systext.obj_id
GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value) AS temp INNER JOIN (SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
FROM obj_int, obj_systext
WHERE obj_int.obj_type=-300
AND obj_systext.obj_type=42
AND obj_int.obj_id=obj_systext.obj_id
GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value) AS temp2 ON temp.int_value = temp2.obj_id;

Gruss
El Bobbele

Antwort 2 von Cool, aber fehler

Danke

Aber es kommt dies:

Server: Nachr.-Nr. 207, Schweregrad 16, Status 3, Zeile 1
Ungültiger Spaltenname 'obj_int'.

gruss kirtas

Antwort 3 von Du bist mein Held

Hallo

Danke nochmals, ich habs geschafft! (es heisst nicht obj_int sondern obj_id (-: )

Nun noch eine Frage:
Bekommen als ausgabe dies (erste zeile):

-300 1 1 Damian Winterthur

Damian und winterthur sind nun aber in der gleichen spalte, wie kann ich diese zwei werte in einzelne Spalten tun ?

gruss und nochmals herzlichen Dank...kirtas

Antwort 4 von El Bobbele

Hallo!

Sorry, für mich sah es so aus, als ob "Damian Winterthur" ein Text sein soll. Ersetze im SQL-Ausdruck dies:
+ ' ' +

durch das:
,<Leerzeichen>


Deine Spaltennamen sind nicht einfach zu lesen vor lauter Kleinschreibung und Unterstriche. :-)

Gruss
El Bobbele

Antwort 5 von Danke schön

Herzlichen Dank, nun ist leider noch was dazu gekommen:

Villeicht kannst du mir ja nen Tip geben: ich möchte diese beide Abfragen zusammenfassen in eine abfrage:

SELECT temp.obj_type, temp2.obj_id, temp.int_value, temp.text_value, temp2.text_value AS text_value
FROM
(SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
FROM obj_int, obj_systext
WHERE obj_int.obj_type=-300
AND obj_systext.obj_type=-300
AND obj_int.obj_id=obj_systext.obj_id
GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value) AS temp INNER JOIN (SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
FROM obj_int, obj_systext
WHERE obj_int.obj_type=-300
AND obj_systext.obj_type=42
AND obj_int.obj_id=obj_systext.obj_id
GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value) AS temp2 ON temp.int_value = temp2.obj_id;




select obj_systext.text_value,
min(obj_date.date_value) mindate,
max(obj_date.date_value) maxdate,
obj_systext.obj_id
from obj_date Left JOIN obj_systext ON obj_date.obj_id=obj_systext.obj_id
where obj_systext.obj_type=-300
and obj_date.obj_type=-300
group by
obj_systext.text_value,
obj_systext.field_id,
obj_systext.obj_id
order by
mindate

--------------Resultat der Abfragen---------------
obj_type,obj_id,int_value,text_value, text_value
-300 1 1 Damian Winterthur
-300 1 1 Kiesten Winterthur
-300 2 2 Homepage Einweihung
-300 2 2 Stadtfest Dietikon
-300 0 0 Fest Wil
-300 3 3 Stefant Zummer



text_value, mindate, maxdate, obj_id

Kiesten 2004-11-03 2004-11-03 1
Damian 2004-11-03 2004-11-03 0
Homepage 2004-11-03 2004-11-03 2
Stadtfest 2004-11-03 2004-11-03 3
fest 2004-11-03 2004-11-03 4
Stefan 2004-11-04 2004-11-04 5

----------------------

verknüpfungspunkte sind:
obj_date.obj_id=obj_systext.obj_id
where obj_systext.obj_type=-300
and obj_date.obj_type=-300


Hast du eine Idee?

gruss und Dank

Antwort 6 von Kirtas

Habe mals dies versucht:
------------------
SELECT temp.obj_type, temp2.obj_id, temp.int_value, temp.text_value, temp2.text_value,temp.obj_id AS text_value
FROM

(SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
FROM obj_int, obj_systext
WHERE obj_int.obj_type=-300
AND obj_systext.obj_type=-300
AND obj_int.obj_id=obj_systext.obj_id
GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value)

AS temp INNER JOIN

(SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
FROM obj_int, obj_systext
WHERE obj_int.obj_type=-300
AND obj_systext.obj_type=42
AND obj_int.obj_id=obj_systext.obj_id
GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value)

AS temp2 INNER JOIN

(Select min(obj_date.date_value) mindate, max(obj_date.date_value) maxdate, obj_systext.obj_id
from obj_date Left JOIN obj_systext ON obj_date.obj_id=obj_systext.obj_id
where obj_systext.obj_type=-300
and obj_date.obj_type=-300
group by
obj_systext.obj_id,
obj_systext.text_value,
obj_systext.field_id)

AS temp3

ON temp.int_value = temp2.obj_id and temp.obj_id = temp3.obj_id
group by temp.obj_type, temp2.obj_id;

--------------------

meldet aber immer nen fehler:
Falsche Syntax in der Nähe des group-Schlüsselwortes.

Was hab ich falsch gemacht?

Antwort 7 von El Bobbele

Moin Kirtas!

Die JOIN-Ausdrücke sind offensichtlich falsch zusammengesetzt.

SELECT temp.obj_type, temp2.obj_id, temp.int_value, temp.text_value, temp2.text_value,temp.obj_id AS text_value
FROM 

(
    (SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
    FROM obj_int, obj_systext
    WHERE obj_int.obj_type=-300
    AND obj_systext.obj_type=-300
    AND obj_int.obj_id=obj_systext.obj_id
    GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value) 

    AS temp INNER JOIN 

    (SELECT obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value
    FROM obj_int, obj_systext
    WHERE obj_int.obj_type=-300
    AND obj_systext.obj_type=42
    AND obj_int.obj_id=obj_systext.obj_id
    GROUP BY obj_int.obj_type, obj_int.obj_id, obj_int.int_value, obj_systext.text_value) 

    AS temp2 ON temp.int_value = temp2.obj_id
)

INNER JOIN 

(Select min(obj_date.date_value) mindate, max(obj_date.date_value) maxdate, obj_systext.obj_id
from obj_date Left JOIN obj_systext ON obj_date.obj_id=obj_systext.obj_id
where obj_systext.obj_type=-300
and obj_date.obj_type=-300
group by
obj_systext.obj_id,
obj_systext.text_value,
obj_systext.field_id)

AS temp3 ON temp.obj_id = temp3.obj_id

group by temp.obj_type, temp2.obj_id;


Syntaktisch sollte das jetzt stimmen. Ob es inhaltlich auch ok ist, kapier ich da eh nicht mehr. *g*

Gruss
El Bobbele