开发者

How to get count of rows returned from nested and WHERE IN used query in MySQL?

SELECT kullaniciNick,
       kullaniciAdi,
       kullaniciSoyadi
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)
ORDER BY kullaniciSoyadi
开发者_StackOverflow中文版

at the query i need the count of rows to check if it is over 6 or less. When i used the COUNT(*) i got an error message. That said it must used with GROUP BY. Thank you.


Try this:

SELECT kullaniciNick,
       kullaniciAdi,
       kullaniciSoyadi,
       count(*) -- Added this line
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)
GROUP BY 1,2,3 -- Added this line
ORDER BY kullaniciSoyadi


You can't have a result, and it's size in one query. Use 2 queries. First one will give you the size of result and second one will be the result. The First query, should be like this:

SELECT count(*)
FROM panelkullanicilari
WHERE id IN
    (SELECT user_id
     FROM proje_ekip
     WHERE proje_id=11)

the second one , is just like the query you wrote above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜