Solved

MAX(UID) in MySQL

Posted on 2015-02-05
8
424 Views
Last Modified: 2015-02-05
I am trying to get the max unique identifier from a table
and I keep getting the first id not the last
Select MAX(UID) as id,UploadDate, Tooltype,SerialNumber,LocationID as 'locid' FROM Inventory_SerializedAssets Where LocationID in(" + otherlocations + ") AND ToolType in ('CO','PT','SS','BG','SP','TN') GROUP BY uid ORDER BY id

Open in new window

0
Comment
Question by:r3nder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 18

Assisted Solution

by:Simon
Simon earned 250 total points
ID: 40591622
You don't need to GROUP BY UID if you want the MAX value for it.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 40591651
I'm not an expert on MySQL, but I think this is what you need:


SELECT UID AS id, UploadDate, Tooltype, SerialNumber, LocationID AS 'locid'
FROM Inventory_SerializedAssets
WHERE LocationID in(" + otherlocations + ") AND
      ToolType in ('CO','PT','SS','BG','SP','TN')
ORDER BY UID DESC
LIMIT 1
0
 
LVL 6

Author Comment

by:r3nder
ID: 40591673
no, sorry that didnt work maybe if  I show you the data

UID | UploadDate              |LocID|SerialNumber|TOOLTYPE|QTY|NOTES                                                 |UserID
842 |2015-02-03 04:22:33|0        |1054                 |CO             |1     |Shipped from Dist 1, received by...|14
843 |2015-02-04 04:27:34|3        |1054                 |CO             |1     |Shipped from Dist 2, received by...|7 <---------This is the one I want
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 6

Author Comment

by:r3nder
ID: 40591683
842 |2015-02-03 04:22:33|0        |1054                 |CO             |1     |Shipped from Dist 1, received by...|14
843 |2015-02-04 04:27:34|3        |1054                 |CO             |1     |Shipped from Dist 2, received by...|7 <---------This is the one I want
546 |2015-01-03 04:22:33|0        |1022                 |CO             |1     |Shipped from Dist 17, received by...|14
588|2015-01-04 04:27:34|3        |1022                 |CO             |1     |Shipped from Dist 2, received by...|7 <---------This is the one I want
etc.............
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40591712
So rather than just the max UID, you need the max UID per SerialNumber?  Or by what criteria?
0
 
LVL 6

Author Comment

by:r3nder
ID: 40591731
I need the max(UID)  for each serialnumber that matches WHERE LocationID in(3,2,1,4) AND
      ToolType in ('CO','PT','SS','BG','SP','TN')
0
 
LVL 6

Author Comment

by:r3nder
ID: 40592107
I figured it out
SELECT UID AS id,
              UploadDate,
              Tooltype,
              SerialNumber,
              LocationID AS 'locid'
FROM Inventory_SerializedAssets
WHERE UID IN(SELECT MAX(UID) FROM Inventory_SerializedAssets GROUP BY SerialNumber)  
              AND LocationID in(" + otherlocations + ")
              AND ToolType in ('CO','PT','SS','BG','SP','TN') GROUP BY SerialNumber
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40592110
Thanks for the help
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question