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 > Less than 4 records

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-02-12, 10:39
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 111
Less than 4 records

I need to show and hide a section on a page only if there are less than 4 records whose memberID is 5. This attempt fails!

SELECT @rownum:=@rownum+1 r
, id_cr2
FROM caseReport_ReCert
, (SELECT @rownum:=-1) r
WHERE memberID = 5
AND r<4

Should I be using different functions?
thanks
nick
Reply With Quote
  #2 (permalink)  
Old 07-02-12, 10:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 20,000
Code:
SELECT id_cr2
  FROM caseReport_ReCert
 WHERE memberID = 5 
GROUP
    BY id_cr2
HAVING COUNT(*) < 4
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-02-12, 11:08
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 111
I would feel better if you made it look harder thanks makes perfect sense, I guess I have to re-read Simply SQl !

ta
Reply With Quote
  #4 (permalink)  
Old 07-02-12, 11:47
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 111
It didn't do what I needed it to do(: What I need is the recordset to be empty if there are less than 4 rows.

thanks
Reply With Quote
  #5 (permalink)  
Old 07-02-12, 12:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 20,000
Quote:
Originally Posted by oldnickj View Post
What I need is the recordset to be empty if there are less than 4 rows.
as far as i know without testing it, that's what my query does

can you provide a test case?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 07-02-12, 12:51
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 823
Try

SELECT id_cr2
FROM caseReport_ReCert
WHERE memberID = 5
GROUP
BY id_cr2
HAVING COUNT(*) > 4
__________________
Ronan Cashell
Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster 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