Jump to content

[SOLVED] GROUP


jaymc

Recommended Posts

When using GROUP how can you get it to return the highest value in one of the affected rows

 

for example, if there are 20 usernames in a table, for each row there is a time field of which are all different

 

if we are doing GROUP BY username, how can I get it to pull out the highest time too

 

At the moment I am unable to have any control of what time field it pulls out. I have tried using ORDER by and MAX() but it doesnt work

Link to comment
Share on other sites

MAX Should work:

 

SELECT username,MAX(time) FROM tablename GROUP BY username

 

That worked, but not when I put the rest in

 

$querya = "SELECT count(views) as count, SUM(views) as viewers, gallery, timestamp, MAX(valid)

FROM gallery

WHERE gallery.user = 'peter'

GROUP BY gallery";

Link to comment
Share on other sites

Sure

 

$q = "SELECT count(views) as count, SUM(views) as viewers, gallery, MAX(valid), timestamp

FROM gallery

WHERE user = 'jamie'

GROUP BY gallery";

 

Or if you mean an example of data returned, well, its not returning the row in that GROUP which has the highest value for valid.

 

Its as if it ignores that altogether

Link to comment
Share on other sites

Ok, its for a gallery system

 

You click on a member and it will display there galleries. They may have 1 gallery they may have 20, it displays each of there gallerys. Of course if you click on one of the gallerys it then goes in and displays all the pictures but thats irrelivent

 

The point is and my problem, I want a certain picture displayed for each of the galleries, the image is the one which has the highest value for valid

 

if there where 10 images and I did a GROUP, it would select one of them images by default

 

I want to choose which image is selects as default

 

As well as doing that, as part of image name from the row returned, I also get the gallery name which is the object

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.