+ 4

I can't understand this IN concept. Can anyone explain it clearly please?

30th Jul 2016, 5:32 AM
Mohamed Hafizullah S
Mohamed Hafizullah S - avatar
13 ответов
+ 14
IN is for selecting multiple values in WHERE clause. Say you want to select people from the cities London and Berlin. SELECT name, address FROM cities WHERE city IN ('London', 'Berlin'); This will then see if the city value is IN the array of values that we provided. You are looking IN an array. Hope this helps.
30th Jul 2016, 1:51 PM
Nathan “Grimston” Pipes
Nathan “Grimston” Pipes - avatar
+ 6
it works like an OR-logical operator. also you can write your statement in this way: SELECT name, address FROM cities WHERE city = 'London' OR city = 'Berlin'; But we programmer are a little bit lazy. So it is easier to work with the IN-operator.
2nd Aug 2016, 1:18 PM
Desql
Desql - avatar
+ 6
IN allows to use comma(",") instead of multiple OR. So you can put "IN (X,Y,Z)" instead of "X OR Y OR Z", getting much more structured and short code.
19th Aug 2016, 8:36 PM
Александр Панков
Александр Панков - avatar
+ 5
To extend Nathans answer: Another use case is where you use it together with a subquery. The following query allows you to get all rows and columns from People that live in Boston and New York without joining the City table or knowing their Ids. SELECT * FROM People as t1 WHERE t1.city_id in (SELECT id FROM city WHERE name in("Boston", "New York") );
1st Aug 2016, 10:59 AM
Johan Sandahl
Johan Sandahl - avatar
+ 2
Simply it means that the particular value is present or not
10th Nov 2018, 11:10 AM
SHREYASH MANDLEKAR
SHREYASH MANDLEKAR - avatar
+ 1
in is simply put as the easiest way in testing the condition OR without the repetition of OR over and over
4th Aug 2016, 7:37 PM
Innocent Egbunu
+ 1
IN is almost OR function with using comma
20th Aug 2016, 10:47 AM
Govindaraj M
0
grate answer and clear
31st Jul 2016, 6:37 PM
Napster Team
Napster Team - avatar
0
basically, it reduces the lines of coding . see, if u r using "or " then u have to write or for every instance but if u use IN SO, U can simply put your search in one bracket separated by commas.
22nd Aug 2016, 1:47 PM
Saurabh Gupta
Saurabh Gupta - avatar
0
IN is OR function. can pergorm OR without using multiple time. Just using comma
22nd Aug 2016, 4:13 PM
Govindaraj M
0
Please let me know which languages are required to be database administrator?
17th Aug 2018, 5:49 PM
Neha Bhalerao
Neha Bhalerao - avatar
0
in case you want to find in the WHERE condition any of the following values, you can use IN(value1, value2, value3, ect) and the result sill be finding any and all records that meet any of thd values(it would be like using an or for the same conditon multiple times)
9th Sep 2018, 9:40 PM
amy
0
Instead of using OR you can use IN using the parenthesis which will shorten the code
19th Jan 2019, 9:29 PM
Suraj Pawar
Suraj Pawar - avatar