Filtering rows using OR operator 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 comes from Mumbai, any one of the two.

| ---------- | ------------ | ------------ | --------------- |
| 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 OR operator in SQL:

SELECT * 
FROM students
WHERE student_country = 'India'
OR student_city = 'Mumbai'

Filtering rows using OR operator 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 == 'India') | (students.student_city == 'Mumbai')]

# Method 2
students.loc[(students.student_country == 'India') | (students.student_city == 'Mumbai')]

# Method 3
students.query('student_country == "India" or student_city == "Mumbai"')

Filtering rows using OR operator in R:

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

# Method 1
students[students$student_country == "India" | students$student_city == "Mumbai",]

# Method 2
students[which(students$student_country == "India" | students$student_city == "Mumbai"),]

# Method 3
subset(students, student_country == "India" | student_city == "Mumbai")

# Method 4
library('dplyr')

filter(students, student_country == "India" | student_city == "Mumbai")

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
5           6        Priya        Delhi           India