I have this below query
SELECT Group_concat(employeename) AS name
FROM employee
WHERE Find_in_set(Find_in_set(employeeid,
(SELECT participantsids
FROM schedule
WHERE validfrom = '2016-04-21 17:00:00'
AND validto = '2016-04-21 17:30:00')
), '1,2');
Which returns me a correct value.. But now I have to check
SELECT participantsids
FROM schedule
WHERE validfrom <= '2016-04-21 17:00:00'
AND validto >= '2016-04-21 17:30:00';
This returns more rows, but I want to include this in my 1st query so I tried this
SELECT Group_concat(employeename) AS name
FROM employee
WHERE Find_in_set(Find_in_set(employeeid,
(SELECT participantsids
FROM schedule
WHERE validfrom <= '2016-04-21 17:00:00'
AND validto >= '2016-04-21 17:30:00')
), '1,2');
This returns error "Subquery returns more than 1 row"
I have tried using ANY and In before the subquery but it shows syntax error and my question is at what point should I correctly use them?
You can try limit
SELECT participantsids
FROM schedule
WHERE validfrom <= '2016-04-21 17:00:00'
AND validto >= '2016-04-21 17:30:00'
LIMIT 1;
in your case i think you are using Find_in_set in an improper way you should use a set notation like this
SELECT Group_concat(employeename) AS name
FROM employee
WHERE ( employeeid,
(SELECT participantsids
FROM schedule
WHERE validfrom <= '2016-04-21 17:00:00'
AND validto >= '2016-04-21 17:30:00'
LIMIT 1) = (1,2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.