Reputation: 149
Good Day. As an example i have a table with 2 fields refid and checksum
I would like to get all the refids where the checksum matches a specific ID
|refid|checksum| |1 | abc |2 | def |3 | hij |4 | def |5 | hij
I then have the refid that i want to match. So if i have refid 2 I want to get all rows that match the checksum colum of the row that matches 2
In 2 queries i would do
Select Checksum FROM t1 WHERE refid = 2
SELECT * FROM t1 WHERE checksum = <result of query 1>
I would like to do this in one query
Upvotes: 2
Views: 2672
Reputation: 28403
You can done this is in two ways
By IN
SELECT * FROM t1 WHERE checksum IN
(Select Checksum FROM t1 WHERE refid = 2)
Or:
By LIMIT
SELECT * FROM t1 WHERE checksum =
(Select Checksum FROM t1 WHERE refid = 2 Limit 1)
Upvotes: 4