Reputation: 361
I'm writing in order to solve a particular SQL query.
Here's my situation: in which way is possible to perform a query that in a WHERE clause allow to identify (from another table) the equality of one field and the > of another?
Something like the IN clause:
select *
from tableX
WHERE (tableX.field1, tableX.field2) IN (select tableY.field1, tableY.field2 from tableY)
In my case I need to identify all filed1X
that are bigger than field1Y
when tableX.field2 = tableY.field2
.
Thanks.
Nico
Upvotes: 1
Views: 105
Reputation: 861
You want a join instead.
SELECT x.*
FROM tableX x
JOIN tableY y on x.field2 = y.field2 AND x.field1 > y.field1
Upvotes: 0
Reputation: 1527
try this:
select *
from tableX as t1, tableY as t2
where(t1.field1 = t2.field1) AND (t1.field2 > t2.field2)
Upvotes: 0
Reputation:
select *
from tableX
WHERE exists (select 42
from tabley
where tableX.field2 = tableY.field2
and tableX.field1X > tableY.field1Y)
Upvotes: 0
Reputation: 231
select tableX.field1
from tableX innerjoin tableY on tableX.field2 = tableY.field2
where tableX.field1 > tabley.field1
Upvotes: 1