* Stig Nørgaard Jepsen > Is it possible to make a query in MySQL, which could return row > 1,3 and 4 based on these conditions?
select distinct t1.textkey, if(t2.textid,t2.languageid,t3.languageid) as languageid, if(t2.textid,t2.textid,t3.textid) as textid, if(t2.textid,t2.textvalue,t3.textvalue) as textvalue from texts t1 left join texts t2 on t2.textkey=t1.textkey and t2.languageid='da' left join texts t3 on t3.textkey=t1.textkey and t3.languageid='en'; I don't know if you always have at least one of 'da' or 'en' for every possible textkey, and what behaviour you would like if you don't. If you always have at least one of them, the statement could be simplified. The above query will return languageid, textid and textvalue for every textkey in the table, including those without 'da' or 'en', for which NULL values are returned. You could add a where clause and test on the t1 table to decide which textkey rows you wanted: "... where t1.languageid in ('en','da');" or maybe "... where t1.textkey = 'kb1';". You should consider an index on the textkey field if this table could be/is big. hth, -- Roger --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php