I am joining two tables together. First table (Parts) contains
PartID, PartName
Second table (Products) contains
ProductID, PartID, Title
The Parts Table contains unique Parts so when I do a select on it, no duplicates are returned. However, when I do something like this
SELECT Parts.PartID, Parts.PartName, ProductID, Products.Title
FROM Parts INNER JOIN Products ON Parts.PartID = Products.PartID
I get a table back with unique ProductIDs, but the same PartID is repeated several times for different ProductIDs. For example a snippet of my results are below:
PartID ---- PartName ---- ProductID ---- Title ----
.....
23 -------- GOG-Green ---- 46 ---------- Goggles Kit 1
23 -------- GOG-Green ---- 47 ---------- Goggles Kit 2
23 -------- GOG-Green ---- 58 ---------- Goggles Kit 3
.....
I want to only get the record here with the highest Product ID. So I would want to only return
23 -------- GOG-Green ---- 58 ---------- Goggles Kit 3
Does anyone know an easy way to do this?
I tried this:
SELECT Parts.PartID, Parts.PartName, [red]MAX(ProductID)[/red], Products.Title
FROM Parts INNER JOIN Products ON Parts.PartID = Products.PartID
But it gave me an error. I'm sure I'm close but a google search didn't return much....
So I know it may be bad database structure but I can't really do much about it at the moment.
PartID, PartName
Second table (Products) contains
ProductID, PartID, Title
The Parts Table contains unique Parts so when I do a select on it, no duplicates are returned. However, when I do something like this
SELECT Parts.PartID, Parts.PartName, ProductID, Products.Title
FROM Parts INNER JOIN Products ON Parts.PartID = Products.PartID
I get a table back with unique ProductIDs, but the same PartID is repeated several times for different ProductIDs. For example a snippet of my results are below:
PartID ---- PartName ---- ProductID ---- Title ----
.....
23 -------- GOG-Green ---- 46 ---------- Goggles Kit 1
23 -------- GOG-Green ---- 47 ---------- Goggles Kit 2
23 -------- GOG-Green ---- 58 ---------- Goggles Kit 3
.....
I want to only get the record here with the highest Product ID. So I would want to only return
23 -------- GOG-Green ---- 58 ---------- Goggles Kit 3
Does anyone know an easy way to do this?
I tried this:
SELECT Parts.PartID, Parts.PartName, [red]MAX(ProductID)[/red], Products.Title
FROM Parts INNER JOIN Products ON Parts.PartID = Products.PartID
But it gave me an error. I'm sure I'm close but a google search didn't return much....
So I know it may be bad database structure but I can't really do much about it at the moment.