mercredi 9 mars 2016

Need max(id) by location but always getting the same value for each location

I am running a query in sqlserver where i need the latest id by location the location is in a different table but i can join on the id. The problem is the values are always the same and not for each location. Here is my query:

SELECT DISTINCT
(select max(id) from t
where p.partname = 'ibiza')locid,
p.partitionkey,
t.partitionkey,
p.partdesc,
p.partname
FROM
t1 t1,
t t
WHERE
t.partitionkey = t1.partitionkey
GROUP BY
t.id,
p.partitionkey,
p.partname,
p.partdesc,

t.partitionkey;

Aucun commentaire:

Enregistrer un commentaire