abhinav singh
abhinav singh

Reputation: 872

query related to in clause

I have two tables:

table 1

table 2

fid and field are same in both tables. I want a query like

select fid 
  from table 1 
 where field in table 1 corresponding to name = dell 
                      and should not have queryorder = 1

Upvotes: 0

Views: 57

Answers (4)

dave
dave

Reputation: 1364

Your question is not clearly worded, but if I'm reading it right, all you want to show is the fid from table 1, where the "name" field in table2 = dell, and the "queryorder" field from table 1 is not equal to "1".

SELECT
   table1.fid
FROM
      table1
   INNER JOIN
      table2
   ON
          table1.fid = table2.fid
      AND table1.field = table2.field
WHERE
       table2.name = 'dell'
   AND table1.queryorder <> 1

Small piece of advice: you should not name a field "name" -- that's a keyword, and will cause you headaches down the road.

Upvotes: 1

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25390

 select t1.fid 
 from table1 t1, table2 t2 
 where t1.fid = t2.fib
 AND t1.field  = t2.field
 and t2.name= 'dell'
 and t1.queryorder <> 1

Upvotes: 0

Mike M.
Mike M.

Reputation: 12551

This looks like it's really just a join, but I can't tell what you're looking for exactly..

SELECT DISTINCT(fid) FROM Table1 T1
JOIN Table2 T2 ON T1.fid = T2.fid
WHERE t2.queryOrder != 1 AND T1.name = 'DELL'

Upvotes: 0

Borealid
Borealid

Reputation: 98559

SELECT fid FROM table1 WHERE name='dell' AND fid NOT IN (SELECT fid FROM table2 WHERE queryorder != 1)

It's very hard to tell what you're asking from the question, there. This will give you all fids where the name in table1 is 'dell' and the queryorder in table2 is not 1.

Upvotes: 0

Related Questions