Solved

MAX(UID) in MySQL

Posted on 2015-02-05
8
411 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
  • 5
  • 2
8 Comments
 
LVL 18

Assisted Solution

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

Accepted Solution

by:
ScottPletcher earned 250 total points
Comment Utility
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
Comment Utility
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
 
LVL 6

Author Comment

by:r3nder
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now