我有一个break和clock_in_out表,我想从两者中获取所有值并将它们连接到user_id列。但是我在JOIN ON附近使用了不正确的synatx,而不是线索为什么..这是我的查询
SELECT *
FROM `breaks`
WHERE `user_id` = 1
AND `in_date` LIKE '%2015-03-03%'
AND `out_date` LIKE '%2015-03-03%'
JOIN `clock_in_out` ON `breaks`.`user_id` = `clock_in_out`.`user_id`
WHERE `loggedin_date`
LIKE '%2015-03-03%'
AND `loggedout_date` LIKE '%2015-03-03%'
答案 0 :(得分:2)
WHERE
子句应在JOIN
之后:
SELECT *
FROM `breaks` JOIN
`clock_in_out` ON `breaks`.`user_id` = `clock_in_out`.`user_id`
WHERE `user_id` = 1
AND `in_date` LIKE '%2015-03-03%'
AND `out_date` LIKE '%2015-03-03%'
AND `loggedin_date` LIKE '%2015-03-03%'
AND `loggedout_date` LIKE '%2015-03-03%'
答案 1 :(得分:1)
您不能混用WHERE
和JOIN
条款。订单为:SELECT
,FROM
,JOIN
,WHERE
,GROUP BY
,HAVING
,LIMIT
。所以它应该是:
SELECT *
FROM `breaks`
JOIN `clock_in_out` ON `breaks`.`user_id` = `clock_in_out`.`user_id`
WHERE `user_id` = 1
AND `in_date` LIKE '%2015-03-03%'
AND `out_date` LIKE '%2015-03-03%'
AND `loggedin_date` LIKE '%2015-03-03%'
AND `loggedout_date` LIKE '%2015-03-03%'
有关完整语法,请参阅MySQL documentation。
答案 2 :(得分:1)
你的语法错了。加入的正确语法是Select ... from .. join ... on ... where
SELECT *
FROM `breaks`
JOIN `clock_in_out` ON `breaks`.`user_id` = `clock_in_out`.`user_id`
WHERE `loggedin_date`
LIKE '%2015-03-03%'
AND `loggedout_date` LIKE '%2015-03-03%'
AND `user_id` = 1
AND `in_date` LIKE '%2015-03-03%'
AND `out_date` LIKE '%2015-03-03%'
答案 3 :(得分:0)
正确的语法如下
SELECT *
FROM `breaks`
JOIN `clock_in_out` ON `breaks`.`user_id` = `clock_in_out`.`user_id`
WHERE `user_id` = 1
AND `in_date` LIKE '%2015-03-03%'
AND `out_date` LIKE '%2015-03-03%'
AND `loggedin_date` LIKE '%2015-03-03%'
AND `loggedout_date` LIKE '%2015-03-03%