开发者

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

开发者 https://www.devze.com 2023-03-22 16:13 出处:网络
SELECT kullaniciNick, kullaniciAdi, kullaniciSoyadi FROM panelkullanicilari WHERE id IN (SELECT user_id FROM proje_ekip
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

精彩评论

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