Setting limit for query with UNION in MySQL

2

I would like to know how I create a limit for a query that uses UNION in MySQL, in my case I want to set LIMIT 5 to the following query:

$friends_a = mysql_query("(SELECT * FROM users WHERE id!='$user_q[id]' AND
id='$friends_1_q[user_one_id]') UNION ALL (SELECT * FROM users WHERE
id!='$user_q[id]' AND id='$friends_1_q[user_two_id]')");

I have tried several codes that I found on the internet and I can not, what should I do?

    
asked by anonymous 29.01.2016 / 21:35

1 answer

0

Maybe this will solve

$friends_a = mysql_query("(SELECT * FROM (SELECT * FROM users WHERE id!='$user_q[id]' AND
id='$friends_1_q[user_one_id]') UNION ALL (SELECT * FROM users WHERE
id!='$user_q[id]' AND id='$friends_1_q[user_two_id]') as tabela limit 5");
    
29.01.2016 / 23:20