How to SQL?

All the SQL FAQ as a Data Scientist

Rahul Lalchandani
Analytics Vidhya

--

Introduction to SQL Syntax

SELECT *
FROM <table>

The following operation means to select all the columns within the table.

*is a wild card operator used to return all rows in a given table.

We are using PostgreSQL as our example but MySQL have similar commands and are just a Google away or you can use this guide

Frequently Asked Questions

1.How to filter by a value?

SELECT *
FROM <table 1>
WHERE <column 1>='value'

WHERE this is a a logical operator and allows you to filter for a given value for a column in a table

2. How to filter for multiple values in a list in SQL?

SELECT <column 1>
FROM <table 1>
WHERE <column 1> IN(value 1, value 2,....)

WHERE <column 1> IN (...) this has IN as an additional operator to filter for multiple values in a list

3. How to search for a value if it contains a certain word in SQL?

Method 1- Using the LIKE operator

SELECT * FROM mytable
WHERE <column1> LIKE '%word1%'
OR <column1> LIKE '%word2%'
OR <column1> LIKE '%word3%'

WHERE <column1> LIKE '%word1%'

Method 2 Using the contains operator

SELECT * FROM MyTable 
WHERE <column1>

--

--