SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Dec 8, 2008, 01:10 #1
- Join Date
- Jan 2005
- Location
- blahblahblah
- Posts
- 1,447
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the best way to know that a table isn't empty
Hi,
I'm looking for the most efficient way to know if a table isn't empty. So far, I just queried it, gathered the result and checked if it was empty or not.
Is there a more efficient way to do it?
Regards,
-jj.
-
Dec 8, 2008, 11:59 #2
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
SELECT COUNT(*) FROM daTable
alternatively,
SELECT acolumn FROM daTable LIMIT 1
-
Dec 8, 2008, 15:40 #3
- Join Date
- Feb 2004
- Location
- Tampa, FL (US)
- Posts
- 9,854
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
select count(*) from datable is best for myisam tables and can be horrible for innodb, but select acolumn from datable limit 1 is very good for myisam tables and best for innodb tables.
so use the second form.Check out our new Industry News forum!
Keep up-to-date with the latest SP news in the Community Crier
I edit the SitePoint Podcast
-
Dec 8, 2008, 17:23 #4
- Join Date
- Oct 2007
- Location
- Boston, MA
- Posts
- 1,480
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
how about
Code:select top 1 myColumn from myTable
-
Dec 8, 2008, 17:42 #5
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
yes, there is a difference
also, TOP doesn't work in mysql
Bookmarks