1

I want to send a select query to a select query and then count the result.

What I want to do is something like this:

SELECT `word_id`, SUM(`is_core`) as `cores` FROM `table` GROUP BY `word_id` ORDER BY  `cores` DESC;

And then I want to send a select query to the query above. Something like this:

SELECT * FROM `THE QUERY ABOVE` WHERE `cores` >1;
SELECT FOUND_ROWS();

Any help will be appreciated.

Alberto
  • 908
  • 2
  • 10
  • 25

2 Answers2

0

Try this..it provide number of total record.

Select count(word_id) from (SELECT `word_id`, SUM(`is_core`) as `cores` 
FROM `table` GROUP BY `word_id` ORDER BY  `cores` DESC having SUM(`is_core`) > 1)
naveen goyal
  • 4,571
  • 2
  • 16
  • 26
  • I get this sql error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'having SUM(`is_core`) > 1)' at line 2 – Alberto Feb 03 '14 at 10:42
0

Why do you use nested queries? You can have same result with a single query.

SELECT `word_id`, SUM(`is_core`) as `cores` 
FROM `table` 
GROUP BY `word_id` DESC 
HAVING `cores` > 1 
ORDER BY  `cores`;
Ergec
  • 11,608
  • 7
  • 52
  • 62
  • I get this sql error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'HAVING `cores` > 1 LIMIT 0, 30' at line 1 – Alberto Feb 03 '14 at 10:42