在结果列中联接表时遇到问题。我有一个工作查询,它使用union组合不同的表,但是当我扩展另一个表时,我得到一个错误,说“使用的select语句有不同的列数”
我的问题是:
(SELECT
IDNumber,
CONCAT(LastName, ', ', FirstName, ' ', Middle) as Name,
CONCAT(EmDesignation, ', ', Department) as Information,
Image,
v.PlateNo as PlateNumber
FROM
tblemployee as e, tblvehicle as v
WHERE
v.RFIDNo LIKE '6424823943'
AND
e.RFIDNo LIKE '6424823943')
UNION
(SELECT
IDNumber,
CONCAT(LastName, ', ', FirstName, ' ', Middle) as Name,
CONCAT(Course, ', ', Year) as Information,
Image,
v.PlateNo as PlateNumber
FROM
tblstudents as s, tblvehicle as v
WHERE
v.RFIDNo LIKE '6424823943'
AND
s.RFIDNo LIKE '6424823943')
我对此有意见。上面的继续查询
UNION
(SELECT
Barrier
FROM
tblinformation as inf
WHERE
inf.RFIDNo IN (6424823943)
ORDER BY
AttendanceNo DESC LIMIT 1)
2条答案
按热度按时间ui7jx7zq1#
错误消息说明问题所在。只要增加select中的列数,它就会正常工作。
hmmo2u0o2#
错误消息是正确的。添加
NULL
s到第二个查询以匹配列号,它将起作用。例如: