To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > General Help > Scripting & Backend

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-25-2006, 11:38 PM   #1
canuckster
Stupid Little Dreamer
 
Join Date: Aug 2000
Location: Toronto
Posts: 582
Can I do this in a single query?

At our website, registered users may choose to sign up for a season of premier membership. I'm trying to write a single query that will show some info about the user, how many premier seasons he or she has signed up for so far, and the date of the latest membership season. Something like, perhaps:
Code:
NAME.......................NUM SEASONS.................LATEST SEASON
JOHN SMITH .................4 .........................SUMMER 2006
I've written a simple query that will do this, but with one important flaw -- instead of showing the latest season, it shows whatever happened to be the first season it found before GROUPing the results. Here's what I mean.

Suppose John Smith has signed up for Fall 2005, Winter 2006, Spring 2006 and Summer 2006, and that the seasons appear in the seasons table in that order. The following query will return John Smith, 4, Fall 2005:

Code:
SELECT USR_username, 
	COUNT(UAS_singleID) AS 'numSeasonsPlayed',
	SEA_longname
FROM users
	JOIN users_and_memberships
		ON USR_userID = UAM_userID
	JOIN seasons
		ON UAM_seasonID = SEA_seasonID
WHERE USR_userID = '100'
GROUP BY USR_userID
ORDER BY SEA_startdate DESC
If I get rid of the COUNTing and merely wish to show John's most recent season, then it's no problem; the following query will return "John Smith, Summer 2006":

Code:
SELECT USR_username, SEA_longname
FROM users
	JOIN users_and_memberships
		ON USR_userID = UAM_userID
	JOIN seasons
		ON UAM_seasonID = SEA_seasonID
WHERE USR_userID = '100'
ORDER BY SEA_startdate DESC
LIMIT 1
I'm assuming that what's going on here is that by the time the ORDER BY is reached, there's now only one record, thanks to the COUNT/GROUP BY combination. So -- other than simply writing a second query and handling things via PHP, is there a way around this? BTW I'm limited to MySQL 4.1.

Many thanks!
__________________
If it weren't for the last minute, nothing would get done ...

Last edited by canuckster; 06-26-2006 at 10:59 AM.
canuckster is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > Scripting & Backend

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:44 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.