Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

number of rows after limit?

Status
Not open for further replies.

JackBowden

IS-IT--Management
Nov 15, 2002
9
0
0
US
consider this query:<br><br>select * from table limit 10<br><br>is there any way of finding out how many rows it would have returned if i hadn't put the limit there? or would i have to do another query without the limit to find out?
 
Yes to both questions - sort of.<br>You can add a subquery to get total.<br>select *, (select count(*) from table)<br>from table <br>limit 10 <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
what about if there was a 'where' clause?<br>i.e. same question but with this query, say:<br><br>select * from table where name = &quot;john&quot; limit 5
 
subqueries behave the same way, so just <br>select *, (select count(*) from table where name = &quot;john&quot; )<br>from table <br>where name = &quot;john&quot; <br>limit 5 <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top