troubleshooting Question

MySql select with sub select needed

Avatar of phillystyle123
phillystyle123Flag for United States of America asked on
PHPMySQL Server
4 Comments1 Solution253 ViewsLast Modified:
MySql select wanted. I have a table with 4 columns labeled id (auto increment), date (date), type (int), sub_type (int), amount (int). The desired result are the records for each type and corresponding subtype with the most recent date entry. Here is an example.

Without the extra complexity of the sub_type the select would be:

SELECT * FROM  yourtable s1 WHERE  date=(SELECT MAX(s2.date) FROM yourtable s2 WHERE s1.type = s2.type)
--
table.jpg
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros