Sql Query über zwei Tabellen

nasdero
Posts: 33
Joined: 2003-07-10 09:03

Sql Query über zwei Tabellen

Post by nasdero »

Hallo Leute,

ich versuche Daten aus zwei Tabellen in einer Abfrage zusammen aus der DB raus zu holen:

SELECT bb1_users.userid, bb1_users.username, bb1_users.birthday, bb1_userfields.userid, bb1_userfields.field6 AS username, bb1_userfields.field7 AS birthday, bb1_userfields.userid, bb1_userfields.field11 AS username, bb1_userfields.field12 AS birthday, bb1_userfields.userid, bb1_userfields.field14 AS username, bb1_userfields.field15 AS birthday
FROM bb1_users, bb1_userfields
WHERE bb1_users.birthday LIKE '%-06-23'
AND bb1_userfields.field7 LIKE '%-06-23'
AND bb1_userfields.field12 LIKE '%-06-23'
AND bb1_userfields.field15 LIKE '%-06-23'
LIMIT 0 , 30


Das Ergebnis ist:

userid username birthday userid username birthday userid username birthday userid username birthday
1 Testuser 2008-06-23 1 Testhund 2007-06-23 1 Testhund2 2006-06-23 1 Testhund3 2005-06-23


ich würde aber gerne sowas haben wollen:

userid username birthday
1 Testuser 2008-06-23
1 Testhund 2007-06-23
1 Testhund2 2006-06-23
1 Testhund3 2005-06-23


Geht das mit Join, oder wie bekomme ich das hin?

Gruß,
Nasdero
Top

nasdero
Posts: 33
Joined: 2003-07-10 09:03

Re: Sql Query über zwei Tabellen

Post by nasdero »

$result = $db->unbuffered_query("SELECT userid, username, birthday FROM bb".$n."_users WHERE birthday LIKE '%-".$currentdate."' UNION SELECT userid, field6 AS username, field21 AS birthday FROM bb".$n."_userfields WHERE field21 LIKE '%-".$currentdate."' UNION SELECT userid, field22 AS username, field23 AS birthday FROM bb".$n."_userfields WHERE field23 LIKE '%-".$currentdate."' UNION SELECT userid, field25 AS username, field26 AS birthday FROM bb".$n."_userfields WHERE field26 LIKE '%-".$currentdate."' UNION SELECT userid, field28 AS username, field29 AS birthday FROM bb".$n."_userfields WHERE field29 LIKE '%-".$currentdate."' ORDER BY username ASC");


UNION war der Befehl der mir gefehlt hat.
Top

dotme
Posts: 150
Joined: 2004-12-15 16:48

Re: Sql Query über zwei Tabellen

Post by dotme »

Oder so?!

Code: Select all

$ grep -r '06-23' .
Top