ich drei Tabellen anschließen mag,mehr als zwei Tabellen verknüpft werden, ohne Werte wiederholen
Ich habe drei Tabellen Benutzer, Beruf und Bildung, in denen „uid“ ist Primärschlüssel für Benutzertabelle und Fremdschlüssel für andere zwei Tabellen. Ich möchte diese Tabellen verbinden in einer einzigen Tabelle zu erzeugen, führen
user profession education
+------+-------+ +-----+----------+ +-----+---------+
| uid | uName | | uid | profName | | uid | eduName |
+------+-------+ +-----+----------+ +-----+---------+
| 1 | aaa | | 1 | prof1 | | 1 | edu1 |
| 2 | bbb | | 1 | prof2 | | 1 | edu2 |
| 3 | ccc | | 2 | prof1 | | 1 | edu3 |
| | | | 3 | prof3 | | 3 | edu4 |
| | | | 3 | prof2 | | | |
+------+-------+ +-----+----------+ +-----+---------+
Expected output
+------+-------+-----+----------+-----+---------+
| uid | uName | uid | profName | uid | eduName |
+------+-------+-----+----------+-----+---------+
| 1 | aaa | 1 | prof1 | 1 | edu1 |
| null | null | 1 | prof2 | 1 | edu2 |
| null | null |null | null | 1 | edu3 |
| 2 | bbb | 2 | prof1 | null| null |
| 3 | ccc | 3 | prof3 | 3 | edu4 |
| null | null | 3 | prof2 | null| null |
+------+-------+-----+----------+-----+---------+
ich Abfrage folgende versucht
select u.uid ,u.uName,p.uid , p.profName,e.uid,e.eduName
from user u inner join profession p on u.uid=p.pid
inner join education e on u.uid = e.uid
where u.uid=p.uid
and u.uid=e.uid
and i.uid=1
Was mich Werte
+------+-------+-----+----------+-----+---------+
| uid | uName | uid | profName | uid | eduName |
+------+-------+-----+----------+-----+---------+
| 1 | aaa | 1 | prof1 | 1 | edu1 |
| 1 | aaa | 1 | prof2 | 1 | edu1 |
| 1 | aaa | 1 | prof1 | 1 | edu2 |
| 1 | aaa | 1 | prof2 | 1 | edu2 |
| 1 | aaa | 1 | prof1 | 1 | edu3 |
| 1 | aaa | 1 | prof2 | 1 | edu3 |
+------+-------+-----+----------+-----+---------+
Gibt es eine Möglichkeit das bekommen duplizieren gibt Ausgabe mit nicht wiederholt die Werte. Danke
Sie möchten die sich wiederholenden Werte. SQL-Ergebnismengen haben keine inhärente Reihenfolge. Die gewünschte Formatierung erfolgt am besten auf der Anwendungsebene. –
mit Blick auf Ihr Ergebnis haben Sie Zeilen nicht dupliziert .. Sie haben Spalte mit rebead Werte .. so, wenn Sie andere Formatierung des Ergebnisses benötigen müssen Sie Client-Seite für die Präsentation – scaisEdge
Ihre Logik für Nullen ist nicht klar. Wenn Sie die gleiche UID für prof1 und prof2 haben, warum hat dann prof1 aaa und prof2 null? Was ist die Logik für den Unterschied im Ergebnis für diese zwei Zeilen? – clinomaniac