If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Advanced SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-04-10, 16:13
NickyT NickyT is offline
Registered User
 
Join Date: Mar 2009
Posts: 3
Advanced SQL

Hello,

Can someone tell me if it's possible to do the following:

Have a query thats Searches through the database and finds tables that have 4 records or less

How can i do this?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 12-04-10, 17:26
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by NickyT View Post
Can someone tell me if it's possible to do the following:
not in a single query

why do you want to do it, may i ask?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-04-10, 23:15
NickyT NickyT is offline
Registered User
 
Join Date: Mar 2009
Posts: 3
Quote:
Originally Posted by r937 View Post
not in a single query

why do you want to do it, may i ask?
Currently I have a php that has users sign up teams. Each team has multiple members. When we run tournaments such as 4v4's for example we wan't to make sure that every team signed up has at least 4 members otherwise they are to be deleted.

Currently we have to do this manually, and when there are many teams, this will become extremely tedious

Thanks.
Reply With Quote
  #4 (permalink)  
Old 12-05-10, 05:19
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
thank you for the explanation, now i understand why you want to do it

you have each team in their own table!!

any chance you can redesign it?

all teams should be in one table

then you can do a single query with a simple GROUP BY, with a HAVING on the COUNT
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 12-13-10, 12:14
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
Have you thought of issuing a query against the information_schema database and in particular the TABLES table. This contains all the tables in every database and also includes a field called TABLE_ROWS. For InnoDB this is an approximation rather than an exact number but for MyISAM this appears to be exact.

Hence, you could simply write the following (assuming you have admin access):

Code:
SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = '<database name>'
AND TABLE_ROWS <= 4;
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On