IN function in Sql query for Sql_Begineers?

Sabarimahesh
Posted by Sabarimahesh under Sql Server category on | Points: 40 | Views : 966
The IN function used to reduce the need to use multiple OR conditions.


The syntax for the IN function


SELECT column_name
FROM table_name
WHERE Column_name1 in (V1, V2, .... Vn);


Statement return the values From (V1, V2, .... Vn)



Example


SELECT * FROM Students WHERE Students_age not in (19,20,21);

you will get except 19,20,21

Comments or Responses

Posted by: Ksuresh on: 4/12/2012 Level:Starter | Status: [Member] | Points: 10
Hi Sabarimahesh,

i need this type of Query but is it possible to pass Array of id's or list of id's in above Query, please can you form query using array or list of id's.

Thanks
Suresh
Posted by: Sabarimahesh on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
Ksuresh

Can You Say Clearly...

i'll Help u
Posted by: Ksuresh on: 4/12/2012 Level:Starter | Status: [Member] | Points: 10
Hi,

SELECT * FROM Students WHERE Students_age not in (19,20,21);


here in above Query u r passing 19,20,21 record id 's na, my requirement is i want to pass in place of records ids array or list which contains some of record id's So is it possible to do like this, becoz i don't i don't know first time i am seeing above Query.

Thanks.
Posted by: Sabarimahesh on: 4/12/2012 Level:Bronze | Status: [Member] | Points: 10
ya its Possible


if you are having two tables

table1

Table 2

table1
id
name
Age
Table 2
id
address
mark_scored

Query
select * from Table 1 where id in(select id from table1)

so, list of table 1 id Going To Check In Table 1...

Login to post response