RemcoDeWit
Programmer
I've a database with product serial numbers and would like to be able to keep track of which product resides on which location.
[tt]+----+-------------+--------+-----------+------------+
| ID | Serialnumber| PartID | LocationID| InstDate |
+----+-------------+--------+-----------+------------+
| 6 | 456123 | 33 | 553 | 2006-01-25 |
| 5 | 456123 | 33 | 3 | 2006-01-20 |
| 4 | 456132 | 33 | 1 | 2006-01-21 |
| 3 | 123456 | 4 | 2 | 2006-01-17 |
| 2 | 123456 | 4 | 80 | 2006-01-18 |
| 1 | 123456 | 4 | 1 | 2006-01-21 |
+----+-------------+--------+-----------+------------+[/tt]
The installation date doesn't need to be enterd in chronical order.
I need an MySQL query which is able to return which Serialnumbers are currenly present on a specific location.
I've used the GROUP BY 'Serialnumber' command but this only returns the last added entry, Not with the last InstDate
With the example above the result should be for locationID 1
[tt]+----+-------------+--------+-----------+------------+
| ID | Serialnumber| PartID | LocationID| InstDate |
+----+-------------+--------+-----------+------------+
| 4 | 456132 | 33 | 1 | 2006-01-21 |
| 1 | 123456 | 4 | 1 | 2006-01-21 |
+----+-------------+--------+-----------+------------+[/tt]
Could anyone help me with the right query?
[tt]+----+-------------+--------+-----------+------------+
| ID | Serialnumber| PartID | LocationID| InstDate |
+----+-------------+--------+-----------+------------+
| 6 | 456123 | 33 | 553 | 2006-01-25 |
| 5 | 456123 | 33 | 3 | 2006-01-20 |
| 4 | 456132 | 33 | 1 | 2006-01-21 |
| 3 | 123456 | 4 | 2 | 2006-01-17 |
| 2 | 123456 | 4 | 80 | 2006-01-18 |
| 1 | 123456 | 4 | 1 | 2006-01-21 |
+----+-------------+--------+-----------+------------+[/tt]
The installation date doesn't need to be enterd in chronical order.
I need an MySQL query which is able to return which Serialnumbers are currenly present on a specific location.
I've used the GROUP BY 'Serialnumber' command but this only returns the last added entry, Not with the last InstDate
With the example above the result should be for locationID 1
[tt]+----+-------------+--------+-----------+------------+
| ID | Serialnumber| PartID | LocationID| InstDate |
+----+-------------+--------+-----------+------------+
| 4 | 456132 | 33 | 1 | 2006-01-21 |
| 1 | 123456 | 4 | 1 | 2006-01-21 |
+----+-------------+--------+-----------+------------+[/tt]
Could anyone help me with the right query?