Getting error #1221 - Incorrect usage of UNION and LIMIT
<p>I'm trying to make union query with this two queries using <code>union</code> between the queries but getting error #121 Incorrect usage of UNION and LIMIT. Please help me to make this union queries to get result both of this queries.</p>

<p>query1:</p>

<pre><code>SELECT t1.TraineeID,
       t2.attnDate,
       MIN(t1.attnTime) AS inTime,
       (CASE WHEN MIN(t1.attnTime) &lt; MAX(t1.attnTime) THEN MAX(t1.attnTime) else '' end) AS outTime,
       (CASE WHEN t5.Slot ='1' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '1')THEN 'P' 
             WHEN t5.Slot ='2' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '2')THEN 'P'
             WHEN t5.Slot ='3' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '3')THEN 'P'
             WHEN t5.Slot ='4' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '4')THEN 'P'
             WHEN t5.Slot ='1' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '1')THEN 'Early Out' 
             WHEN t5.Slot ='2' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '2')THEN 'Early Out'
             WHEN t5.Slot ='3' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '3')THEN 'Early Out'
             WHEN t5.Slot ='4' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '4')THEN 'Early Out'
             ELSE 'Late-In'
       END) AS Status

FROM tbl_attn_temp t1, tbl_assigned t3, tbl_batch t5
JOIN (SELECT DISTINCT attnDate FROM tbl_attn_temp) t2
WHERE t1.attndate = t2.attnDate and t3.BatchID=t5.BatchID AND t1.TraineeID = t3.TraineeID
AND t1.attnDate='2016-01-13'
AND(CASE WHEN t5.Slot ='1' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '1') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '1') 
         WHEN t5.Slot ='2' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '2') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '2')
         WHEN t5.Slot ='3' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '3') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '3')
         WHEN t5.Slot ='4' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '4') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '4')
    END)
GROUP BY t1.TraineeID, t2.attnDate
</code></pre>

<p>query2:</p>

<pre><code>SELECT t1.TraineeID,
       t2.attnDate,
       MIN(t1.attnTime) AS inTime,
              (CASE WHEN MIN(t1.attnTime) &lt; MAX(t1.attnTime) THEN MAX(t1.attnTime) else '' end) AS outTime,
       (CASE WHEN t4.Slot ='1' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '1')THEN 'P' 
             WHEN t4.Slot ='2' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '2')THEN 'P'
             WHEN t4.Slot ='3' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '3')THEN 'P'
             WHEN t4.Slot ='4' AND t1.attnTime&lt;=(SELECT inTime FROM tbl_threshold WHERE id = '4')THEN 'P'
             WHEN t4.Slot ='1' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '1')THEN 'Early Out' 
             WHEN t4.Slot ='2' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '2')THEN 'Early Out'
             WHEN t4.Slot ='3' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '3')THEN 'Early Out'
             WHEN t4.Slot ='4' AND max(t1.attnTime)&lt;(SELECT outTime FROM tbl_threshold WHERE id = '4')THEN 'Early Out'
             ELSE 'Late-In'
       END) AS Status

FROM tbl_attn_temp t1, tbl_assigned t3, tbl_instructor_info t4
JOIN (SELECT DISTINCT attnDate FROM tbl_attn_temp) t2
WHERE t1.attndate = t2.attnDate AND t1.TraineeID = t4.InstructorID
AND t1.attnDate='2016-01-13'
AND(CASE WHEN t4.Slot ='1' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '1') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '1') 
         WHEN t4.Slot ='2' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '2') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '2')
         WHEN t4.Slot ='3' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '3') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '3')
         WHEN t4.Slot ='4' THEN t1.attnTime BETWEEN(SELECT minLimit FROM tbl_threshold WHERE id = '4') AND (SELECT maxLimit FROM tbl_threshold WHERE id = '4')
    END)
GROUP BY t1.TraineeID, t2.attnDate
</code></pre>