Nko
Nko

Reputation: 361

SQL WHERE IN CLAUSE

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

Answers (4)

Michael Ford
Michael Ford

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

Hadi Sharifi
Hadi Sharifi

Reputation: 1527

try this:

select *
from tableX as t1, tableY as t2
where(t1.field1 = t2.field1) AND (t1.field2 > t2.field2)

Upvotes: 0

user330315
user330315

Reputation:

select * 
from tableX
WHERE exists (select 42 
              from tabley 
              where tableX.field2 = tableY.field2
                and tableX.field1X > tableY.field1Y)

Upvotes: 0

Rbit
Rbit

Reputation: 231

select tableX.field1 
from tableX innerjoin tableY on tableX.field2 = tableY.field2
where tableX.field1 > tabley.field1

Upvotes: 1

Related Questions