Hi, I was wondering why limit is not working on this mysql query
select count(id) as total from wp_posts where post_status='publish' limit 10;
I got more than a thousand records and I want to limit the returned result into 10 records only but still does return more than a thousand records counts.
It will only return 1 result, total = x, due to the use of count(). Limit does not apply when count() is used in this manner. This query is only asking for the total number of published posts, nothing else.
If youâre expecting more than one row, then itâs the wrong query. Why donât you explain what data you want returned in the resultâŚ
The way I see it working (not tested) is there will be one row returned with the value â10â
A pointless query if there are 10 or more fields meeting the WHERE, but until darksystem returns to clarify what is really wanted here, I donât have any advice.
Hate to be pedantic, but using limit on a query than can only return one row is redundant, serves no purpose, pointless, does not apply. Could you explain the value of limit that you interpret in the OPs query?
Your explanation isnât very clear and is full of contradictions. Please forget the query and tell me what data you want and how it will be used in the web page.
[quote=âmetho, post:8, topic:103491, full:trueâ]Could you explain the value of limit that you interpret in the OPs query?
[/quote]sure, iâd be happy to give you my interpretation
[quote=âdarksystem, post:9, topic:103491, full:trueâ]
So pls help how to limit the counted rows?[/quote]
well, you could do this âSELECT LEAST(COUNT(id),10) AS total
FROM wp_posts
WHERE post_status='publish'but i donât see how this would be a useful number to show
It looks like the query is an attempt to get two different things.
IMHO it should get either the count() if the number of rows is wanted or, 10 rows based on WHERE criteria @darksystem Sorry, but I donât understand which it is youâre after.