In MySQL, how do I select distinct records, but still select more data?
-
In MySQL, I want to select emails, firstname, date, etc from past orders where the email is unique. I then want to show other fields for that same row with the first match (the oldest) in the database. For example: Example Real Data: ID, Email, Name, ORDER DATE 1, [email protected] , Mark, 12-2-09 2, [email protected], Jim, 1-5-10 3, [email protected], Mark, 2-3-10 4, [email protected], Bob, 2-9-10 5, [email protected], Mark, 3-1-10 Of the above data, I only want it to show distinct my email, but the other info still there: Example Distinct Data: ID, Email, Name, ORDER DATE 1, [email protected] , Mark, 12-2-09 2, [email protected], Jim, 1-5-10 4, [email protected], Bob, 2-9-10 Do you know the correct MySQL query for this? Thanks!
-
Answer:
SELECT ID,email,Name,MAX(ORDER_DATE) lastorder FROM table GROUP BY email
fiber at Yahoo! Answers Visit the source
Related Q & A:
- How can I insert posted data into the database?Best solution by Stack Overflow
- How do I randomly select a string from an array in swift?Best solution by Stack Overflow
- Why am I receiving a malformed text data error and how do I fix it?Best solution by Yahoo! Answers
- How do I find free public records?Best solution by Yahoo! Answers
- How do I go about getting adoption records?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.