0

也许我只是太久没有做 LEFT JOIN,但我很困惑。

这是我的表:

Table: user_phones

user    phone       carrier
----------------------------
danny   5045551234  Verizon
mom     5551234567  T-Mob
tony    5121234567  T-Mob

Table carriers

carrier    email_exchange
--------------------------
Verizon    vtext.com
T-Mob      tmomail.net

这是我的查询:

SELECT user, CONCAT(phone, '@', email_exchange) AS sms
LEFT JOIN carriers ON (user_phones.carrier = carriers.carrier)
FROM user_phones

我不断回来:

'左加入运营商(user_phones.carrier =运营商.运营商)从user_phones'

我知道这是一个愚蠢的疏忽,但变化没有帮助(将ON条款放在括号中等)不起作用。

我在哪里滑倒?

4

3 回答 3

3

你错过了FROM user_phones

SELECT a.`user`, 
       CONCAT(a.`phone`, '@', b.`email_exchange`) AS sms
FROM user_phones a LEFT JOIN carriers b 
        ON a.carrier = b.carrier
于 2012-05-23T00:23:52.767 回答
1

把你的FROM条款放在你的前面LEFT JOIN

SELECT `user`, CONCAT(phone, '@', email_exchange) AS sms
FROM user_phones LEFT JOIN carriers ON user_phones.carrier = carriers.carrier

一个小建议是id在表中使用自动增量字段carriers,更新user_phones.carrier以保存这些ids,然后加入。高温高压

于 2012-05-23T00:19:42.393 回答
0

尝试:

SELECT user, CONCAT(phone, '@', email_exchange) AS sms
FROM user_phones
LEFT JOIN carriers ON (user_phones.carrier = carriers.carrier)

w3schools - 左连接

于 2012-05-23T00:19:53.503 回答