Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL select with statements

Tags:

sql

select

mysql

I'm learning some more SQL, and ran into a "problem",

I have two tabels like the link below http://www.sqlfiddle.com/#!2/403d4/1

EDIT: Since I'm quite retarded now from all SQL-test i have done this weekend, i asked really wrong... Sorry guys...

What i really wanted:

If i have the requested language, i want to get all the records, and if the requested language is not in the titles-table, i want it to say "" or null...

like if i ask for all records in 'de', i want:

1  |  ACHTUNG
2  |  NULL

and if i ask for all the records in 'en' i want

1  |  WARNING
2  |  Ambulance

Really sorry for the wrong question.

/* What i want to do: I have the ID of a record and the requested language. If the selected language does not exsists, i want it to take the other language.

like if i have: language = 'de' and id = 1 I want 'ACHTUNG',

if i have: language = 'de' and id = 2 i want "Ambulance" since there's no 'de'... */

How do i do this?

like image 513
gubbfett Avatar asked Mar 24 '26 21:03

gubbfett


1 Answers

http://www.sqlfiddle.com/#!2/403d4/89

SELECT rec.id, title.name
FROM Records rec
LEFT JOIN Titles title ON title.record_id = rec.id and title.language='de';

SELECT rec.id, title.name
FROM Records rec
LEFT JOIN Titles title ON title.record_id = rec.id and title.language='en';


ID  NAME
1   ACHTUNG
2   (null)

ID  NAME
1   Warning
2   Ambulance
like image 194
Nesim Razon Avatar answered Mar 26 '26 10:03

Nesim Razon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!