Filtering rows using list of values in SQL, Python and R

Given a table or dataframe named students as shown below, get all the records from the table or dataframe where the student hails from India or Italy.

| ---------- | ------------ | ------------ | --------------- |
| student_id | student_name | student_city | student_country |
| ---------- | ------------ | ------------ | --------------- |
| 1          | John         | Atlanta      | USA             |
| ---------- | ------------ | ------------ | --------------- |
| 2          | Hari         | Mumbai       | India           |
| ---------- | ------------ | ------------ | --------------- |
| 3          | Ali          | Dubai        | UAE             |
| ---------- | ------------ | ------------ | --------------- |
| 4          | Jenny        | Berlin       | Germany         |
| ---------- | ------------ | ------------ | --------------- |
| 5          | Lisa         | Berlin       | Germany         |
| ---------- | ------------ | ------------ | --------------- |
| 6          | Priya        | Delhi        | India           |
| ---------- | ------------ | ------------ | --------------- |
| 7          | Wong         | Beijing      | China           |
| ---------- | ------------ | ------------ | --------------- |
| 8          | Julius       | Rome         | Italy           |
| ---------- | ------------ | ------------ | --------------- |
| 9          | Alonso       | Atlanta      | USA             |
| ---------- | ------------ | ------------ | --------------- |
| 10         | Noor         | London       | UK              |
| ---------- | ------------ | ------------ | --------------- |

Filtering rows using list of values in SQL:

SELECT * 
FROM students
WHERE student_country IN ('India', 'Italy')

Filtering rows using list of values in Python:

You must have the pandas library installed to run this snippet of code.

import pandas as pd

# Method 1
students[students.student_country.isin(['India', 'Italy'])]

# Method 2
students.loc[students.student_country.isin(['India', 'Italy'])]

Filtering rows using list of values in R:

You must have the dplyr library installed to run method 4.

# Method 1
students[students$student_country %in% c('India', 'Italy'), ]

# Method 2
subset(students, students$student_country %in% c('India', 'Italy'))

# Method 3
students[which(students$student_country %in% c('India', 'Italy')), ]

# Method 4
library('dplyr')

filter(students, students$student_country %in% c('India', 'Italy'))

Result:

The following output has been taken directly from a Python, SQL or R console using one of the methods demonstrated above. Hence, the way the result is displayed may not look exactly like the one below for all cases always.

  student_id student_name student_city student_country
1          2         Hari       Mumbai           India
2          6        Priya        Delhi           India
3          8       Julius         Rome           Italy