Question: I have a table structure like the following

```
idx   p_id    location_id  

1     CTX      A1
2     CTX      A2
3     ABC      A3
4     ABC      A1

```

idx is auto increment number and indicating the latest location
(for product CTX case, it transfered from A1 to A2)

NOW, what I want to find is any product in location A1.
I should find only product ABC, since product CTX moved from A1 to A2, it no longer in the A1

Is there easy way to perform with SQL query?

Answer: 
Okay, after re-reading your question, I think this is more what you need:

```
SELECT idx, p_id, location_id
FROM tablename t0 JOIN (
  SELECT MAX(idx) AS m
  FROM tablename
  GROUP BY p_id) t1
  ON t0.idx = t1.m
WHERE t0.location_id = 'A1';

```
The dumbest way:

```
SELECT TOP 1 PRODUCT_ID
FROM YOUR_TABLE
WHERE
 LOCATION_ID = "A1" -- of course use parameter in real application!
ORDER BY
 ID DESC

```

HOWEVER! This is incorrect because one can not safely rely on sequencing of IDS,(even if it works in 99% of cases). Why don't you add a timestamp column? 

You can also use a MAX() function to get a subquery returning max ID:

```
SELECT PRODUCT_ID
 FROM YOUR_TABLE
 WHERE
 LOCATION_ID = "A1" -- of course use parameter in real application!
AND
 ID = SLECT MAX(ID) FROM YOUR_TABLE WHERE LOCATION_ID = "A1"

```