Jump to content

Need Help Using The Distinct, But Needing More Columns Than The Distinct Column


Recommended Posts

I've used the following

 

$sql_select = "select DISTINCT NUMBER1 from Data where check1='1' and userid='" . $param['userid'] . "' order by timestamp asc";

 

 

-----

It correctly gets the data for just the distince values from NUMBER1, but I would like to grab more data that is not necessarily distinct... like the TIMESTAMP, or even the persons name depending on how my user has entered it, they may have entered it with a first and last name or just a first name, so I only want to grab one instance of it.....

 

Thanks in advance

You could use GROUP BY

 

SELECT number1, timestamp, firstname, lastname
FROM Data
WHERE check1='1' AND userid='{$param['userid']}'
GROUP BY number1
ORDER BY timestamp 

 

However, if several people have the same number1, you will only see one of them

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.