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 > MAx records

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-07-10, 17:11
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
MAx records

I want to limit my client to creating ten records. Once they have created ten records I will hide the insert form.

I tried using count() and limiting count but that dosen't work. CAn anyone point e in the right direction?

Thanks

Nick
Reply With Quote
  #2 (permalink)  
Old 11-07-10, 17:12
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
I should add that if the have ten record thenI would let them delete ont if they wanted to add another.
Reply With Quote
  #3 (permalink)  
Old 11-07-10, 17:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by oldnickj View Post
I should add that if the have ten record then I would let them delete one if they wanted to add another.
by un-hiding the delete form?

the mere fact that you are implementing some logic (hiding) in the application code suggests that you could easily handle the 10-row limit there as well

just do a SELECT COUNT(*) before deciding whether to hide or show the insert form
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 11-07-10, 18:02
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
I've over simplified what I'm trying to do.
I wan the query to return nothing if the count is greater then 10 OR only return results if there are ten or more records.

This dosn't work of course:

SELECT COUNT(*) AS C
FROM image_img
WHERE C>10

Nick
Reply With Quote
  #5 (permalink)  
Old 11-07-10, 18:06
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by oldnickj View Post
I wan the query to return nothing if the count is greater then 10 OR only return results if there are ten or more records.
but those two options are diammetrically opposite to each other

let's try the first one
Code:
SELECT CASE WHEN COUNT(*) > 10
            THEN NULL
            ELSE COUNT(*) END AS thecount   
  FROM image_img
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 11-07-10, 18:35
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
The recordset still has one record "NULL". What I need to an empty recordset if they have 10 records, If they have fewer than ten then return *


SELECT CASE WHEN COUNT(*) >10
THEN NULL
ELSE COUNT(*) END AS thecount
FROM image_img

WHERE artist_img=101


Thanks

Nick
Reply With Quote
  #7 (permalink)  
Old 11-07-10, 18:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by oldnickj View Post
What I need to an empty recordset if they have 10 records, If they have fewer than ten then return *
Code:
SELECT *
  FROM image_img
 WHERE artist_img = 101 
   AND 10 > 
       ( SELECT COUNT(*) 
           FROM image_img
          WHERE artist_img = 101 )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 11-07-10, 19:05
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Beautiful! Thanks very much
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