我有两张桌子:
checkinout
Userid | Checktime | Checktype | VERIFYCODE | SENSORID | Memoinfo | WorkCode | sn |
userinfo
Userid | Name | Gender
我想从userinfo表中获取列名,并将其插入checkinout表,对应于他们的Userid,checkinout.userid=userinfo.userid
以下是我的查询,但我在userinfo周围遇到语法错误,你能说出我错过了什么吗?
语法错误:意外' userinfo' (标识符)
SELECT checkinout.USERID, checkinout.CHECKTIME, checkinout.CHECKTYPE,checkinout.VERIFYCODE, checkinout.SENSORID, checkinout.Memoinfo, checkinout.WorkCode, checkinout.sn, userinfo.name
from bio_raw.checkinout, bio_raw.userinfo
join bio_raw.userinfo
on checkinout.userid = userinfo.userid
答案 0 :(得分:3)
SELECT
cio.`userid`,
cio.`checktime`,
cio.`checktype`,
cio.`memoinfo`,
cio.`sensorid`,
cio.`sn`,
cio.`verifycode`,
cio.`workcode`,
ui.`name`,
ui.`gender`
FROM
checkinout cio
INNER JOIN userinfo ui
ON ui.`userid` = cio.`userid`
答案 1 :(得分:2)
你不能混合explizit和implizit join:
SELECT CI.USERID
,CI.CHECKTIME
,CI.CHECKTYPE
,CI.VERIFYCODE
,CI.SENSORID
,CI.Memoinfo
,CI.WorkCode
,CI.sn
,UI.NAME
FROM bio_raw.checkinout AS CI
JOIN bio_raw.userinfo AS UI ON CI.userid = UI.userid
答案 2 :(得分:1)
在第crumb
行中,删除from bio_raw.checkinout, bio_raw.userinfo
, bio_raw.userinfo
时,JOIN
无需提及多个表名。FROM
,CI
。工作代码将是:
UI
答案 3 :(得分:1)
当你想加入2个表时,不需要将它们全部放在FROM
param中。
SELECT checkinout.USERID, checkinout.CHECKTIME, checkinout.CHECKTYPE,checkinout.VERIFYCODE, checkinout.SENSORID, checkinout.Memoinfo, checkinout.WorkCode, checkinout.sn, userinfo.name
from bio_raw.checkinout
join bio_raw.userinfo
on checkinout.userid = userinfo.userid
答案 4 :(得分:1)
userinfo
子句中不需要提及FROM
表。使用以下查询,我相信它应该有效:
SELECT checkinout.USERID, checkinout.CHECKTIME, checkinout.CHECKTYPE,checkinout.VERIFYCODE, checkinout.SENSORID, checkinout.Memoinfo, checkinout.WorkCode, checkinout.sn, userinfo.name
from bio_raw.checkinout
join bio_raw.userinfo
on checkinout.userid = userinfo.userid;