我是MySQL的新手,我只想在两个表中的移动电话号码相同时才从两个表中返回数据。我不要任何null
值。我怎样才能做到这一点?
例子:
Table A
UserID CandidateName CurrentMobile CurrentDistrict Email Centre
1 Max 98234 Chennai [email protected] A
2 Raju 97364 Salem [email protected] B
3 Ramesh 99873 Trichy [email protected] C
Table B
Name MobileNumber District
Maximus 98234 Salem
Ramesh 99873 Trichy
Venkat 98376 Chennai
我想要以下结果:
UserID CandidateName Name CurrentDistrict District Email Centre MobileNumber
1 Max Maximus Chennai Salem [email protected] A 98234
3 Ramesh Ramesh Trichy Trichy [email protected] C 99873
我尝试使用UNION
,但是它null
在某些列中提供值,并且还从两个表中返回所有数据。
您想要在与以下条件A.CurrentMobile
相同的情况下联接两个表B.MobileNumber
:
SELECT
A.UserID,
A.CandidateName,
B.Name,
A.CurrentDistrict,
B.District,
A.Email,
A.Centre,
B.MobileNumber
FROM
A,
B
WHERE
A.CurrentMobile = B.MobileNumber
或者,您可以使用以下语法获得相同的结果:
SELECT
... (all the same fields again)
FROM
A
INNER JOIN B ON A.CurrentMobile = B.MobileNumber
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句