我有两张桌子: perfil(个人资料)和用户
在perfil上,我有一个user_id列,表示指定的用户。
我正在尝试使用user.user(例如kevinkouketsu)在perfil.user_id上使用的user.id
SELECT perfil.*, userId.*, r.Nome as cityName, userId.id as userId
FROM perfil
LEFT JOIN (SELECT * FROM user WHERE user='SOMEVALUE') as userId ON perfil.user_id=userId.id
LEFT JOIN municipio AS r ON perfil.city=r.Codigo
我制作了这段代码,并在perfil表上生成了所有内容,并且别名userId结果为NULL。
结果示例:
array (size=20)
'id' => null
'user_id' => string '1' (length=1)
'conjuge' => string 'Alice Elias Patrício' (length=21)
'conjuge_aniver' => string '2018-02-24 20:49:10' (length=19)
'state' => string 'SC' (length=2)
'city' => string '4217709' (length=7)
'perfil_img' => string '' (length=0)
'user' => null
'senha' => null
'email' => null
'nome' => null
'access' => null
'type' => null
'empresa_id' => null
'rede_id' => null
'birthday' => null
'created' => null
'phone' => null
'cityName' => string 'Sombrio' (length=7)
'userId' => null<