Subquery returns more than 1 row

I have the following request

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 the 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 first 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 the error "Subquery returns more than 1 row"

I tried using ANY and B before the subquery, but it shows a syntax error, and my question is at what point should I use them correctly?

+4
source share
1 answer

You can try to limit

 SELECT participantsids 
 FROM schedule 
 WHERE validfrom <= '2016-04-21 17:00:00' 
     AND validto >= '2016-04-21 17:30:00'
 LIMIT 1; 

, , Find_in_set ,

  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); 
+2

All Articles