![]() |
![]() |
|
![]() |
![]() |
|
Programmierung Rat & Tat für Programmierer |
![]() |
|
Themen-Optionen | Ansicht |
|
![]() |
#1 |
Inventar
![]() Registriert seit: 13.06.2001
Beiträge: 1.830
|
![]() Tabelle: tab
Code:
UID | category | title | other | copyof 1 | a | asd | foo 0 2 | b | fgh | bar 0 3 | | jkl | 2 4 | c | yxc | qwe 0 5 | c | vbn | rtz 2 Meine Lösung ist jetzt in der Form: SELECT uid, 0 as orig_id, category, NULL as orig_category, title, NULL as orig_title, other, NULL as orig_other FROM tab WHERE copyof = 0 UNION SELECT copy.uid, orig.uid as orig_id, copy.category, orig.category as orig_category, copy.title, orig.title as orig_title, copy.other, orig.other as orig_other FROM tab AS orig, tab AS copy WHERE copy.copyof = orig.uid Das liefert: Code:
uid | orig_uid | category | orig_category | title | orig_title | other | orig_other 1 | 0 | a | NULL | asd | NULL | foo | NULL 2 | 0 | b | NULL | fgh | NULL | bar | NULL 4 | 0 | c | NULL | yxc | NULL | qwe | NULL 3 | 2 | | b | jkl | fgh | | bar 5 | 2 | c | b | jkl | fgh | rtz | bar SELECT uid, 0 as orig_id, category, NULL as orig_category, title, NULL as orig_title, other, NULL as orig_other FROM tab WHERE copyof = 0 AND category = 'b' UNION SELECT copy.uid, orig.uid as orig_id, copy.category, orig.category as orig_category, copy.title, orig.title as orig_title, copy.other, orig.other as orig_other FROM tab AS orig, tab AS copy WHERE copy.copyof = orig.uid WHERE ((copy.category = '' AND orig.category = b) OR (copy.category = 'b')) und liefert: Code:
uid | orig_uid | category | orig_category | title | orig_title | other | orig_other 2 | 0 | b | NULL | fgh | NULL | bar | NULL 3 | 2 | | b | jkl | fgh | | bar jak
____________________________________
Join the DNRC | Godwin\'s Law (thx@stona) Documentation is like sex: If it\'s good, it\'s very, very good. If it\'s bad, it\'s better than nothing. \"In theory, theory and practice are the same. In practice, they are not\" (Lawrence Berra) |
![]() |
![]() |
![]() |
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
|
|