mysql with select,MySQL select with语句

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?

解决方案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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值