I hope you are practising SQL whilst you are learning it. This technique makes it easier to understand concepts.

Alrighty, here is another thread for SQL. 🀩

SQL - A Beginner-friendly version! πŸ“š
(Clauses: IN, BETWEEN and LIKE)

Thread 🧡
🌟Which table are we working on today?
The name of the table is "products". So the columns that we have are productCode, productName, productDescription, among others.

Take a look πŸ‘‡ Column namesOverview of the information in the columns
β˜‘οΈ IN
This clause would reduce the efforts to write multiple OR conditions. It helps you find a specific match for a value.

πŸ‘‰ select column1, column2 from table_name where EXPRESSION IN ('value1', 'value2')
Query: Extract the columns productName, buyPrice and productLine where the productLine has values as: 'motorcycles' or 'classic cars'.

Without IN clause: select productName, buyPrice, productLine from products where productLine = "Motorcycles" or productLine = "Classic Cars"; Result without the IN clause.
using IN clause:-
select productName, buyPrice, productLine from products where productLine in ("Motorcycles", "Classic Cars");

We have reduced the multiple OR conditions, so quickly. using IN clause.
β˜‘οΈ NOT IN
This clause can be used to simply negate the results of the IN clause.

Query: Extract the columns productName, buyPrice and productLine where the productLine DOES NOT have values: 'motorcycles' or 'classic cars'.
SQL query: select productName, buyPrice, productLine from products where productLine not in ("Motorcycles", "Classic Cars"); not in clause
β˜‘οΈ BETWEEN
This clause can be used to replace the combination of the "greater than equal AND less than equal" condition.

It will return the rows where the expression is within the range of val1 and val2, inclusive.
πŸ‘‰ select col1, col2, col3.. from table_name where col_name BETWEEN value1 AND value2;

These values can be numbers, texts or dates.

Query: Extract results for buyPrice between 40 & 50.

SQL Query: select productName, buyPrice from products where buyPrice BETWEEN 40 AND 50;
β˜‘οΈ NOT BETWEEN
This clause would negate the results we would obtain from using BETWEEN clause. In other words, using NOT BETWEEN would give results other than the between val1 and val2, inclusive.
β˜‘οΈ LIKE
This clause is used in a WHERE clause to match a specified pattern in a column.

Two operators used using LIKE clause:
% -> It represents 0, 1 or multiple characters (0 to n)

_ -> The underscore operator represents a single character
πŸ‘‰ select col_name(s) from table_name where column LIKE pattern;

Here, pattern means that you have to specify the kind of pattern you want the query to look up for you.
🌟 We will use another table for this.
The name of the table is "customers". Take a look at the columns and values the columns holds to get an idea.
Query: List customers that start with 'c' and end with 'co.'

SQL query: select customerName from customers where customerName like "c%co.";

Explanation: The character 'c' and 'co.' would have 0 to n number of characters between them. To handle that we use % operator. LIKE clause
Some Examples:

1. like "_ss%" πŸ‘‰ any single character before the two 's' and any number of characters after the two 's' at 2nd and 3rd position.
Eg: assuage

2. like "s___p" πŸ‘‰ any three characters between the letters s and p (at 1st and 5th position respectively).
Eg: scalp

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Sukriti Macker

Sukriti Macker Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Sukriti_Macker

24 Jun
Here is another thread of the most important clauses to boost your SQL queries to the next level!

Advance SQL, A beginner-friendly version! (#DataScience)

Thread 🧡
Let me explain what the table looks like.
The table name is customer_list, where the columns are ID, name, address, zip code, phone, city, country, notes & SID.

See the image for reference The table and column names in that table.
β˜‘οΈ GROUP BY
This clause is used to group rows that have the same values together. It summarises data from the database.

Note: The group by clause returns one row for each group.

πŸ‘‰ Query: select col_name from table_name GROUP BY column_name;
Read 13 tweets
14 Jun
Hey, folks! Some time back, I was scrolling through LinkedIn and found some essential SQL topics to revisit before an Interview.

Have a look πŸ§΅πŸ‘‡
1. WHERE, AND, OR, NOT, IN
2. ORDER BY, ASC, DESC
3. IS NULL
4. LIMIT
5. MIN, MAX, COUNT, AVG, SUM
6. LIKE, WILDCARDS
7. IN BETWEEN
8. INNER JOIN
9. LEFT JOIN
10. UNION ALL
11. GROUP BY
12. HAVING
13. LEFT, RIGHT, MID, CONCAT
14. PARTITION BY, OVER
15. LEAD, LAG
16. Subqueries
17. RANK, DENSE_RANK, PERCENT_RANK
18. ROW_NUMBER, CUME_DIST
19. FIRST_VALUE, LAST_VALUE
20. AS
Read 5 tweets
10 Jun
Let's dive further into SQL to help you through the most demanding skill required in the Data Science Industry.

A Beginner's Guide to Filter Results in MySQL - Part 5!!

Thread 🧡
β˜‘οΈ LIMIT Clause
To restrict the number of rows in the final result, we use the LIMIT clause.
That means if you have 10,000 rows in the data, you can fetch only 10 rows using this clause in your query.
πŸ‘‰ Query: select * table_name LIMIT limit_no;

For e.g., Consider a table PAYMENTS. It has more than 1000 rows. [See the image] Table PAYMENTS with 1000 rows.
Read 8 tweets
9 Jun
Have you found the concepts of JOINS in SQL tricky? πŸ˜΅β€πŸ’«

A Beginner-Friendly JOINS guide that would help you in your SQL & Data Science Journey.

Thread 🧡
β˜‘οΈ JOINS (Some Theory)
Using JOIN, we can query data from two or more tables based on the related column present in both tables.

While performing a join, we need to specify the shared column & the condition on which we want to join tables.
β˜‘οΈ Types of JOINS:-
1. Inner Join
2. Left Join
3. Right Join
4. Full Join
Read 14 tweets
7 Jun
Want to pursue Data Science? SQL is the most imperative skill required in it!

A Beginner's Guide to MySQL Queries part 4! πŸ“–
RETRIEVAL & LOADING the data!

Thread 🧡
βœ… RETRIEVE THE DATA

The SELECT command allows the retrieval of information as per our requirements.

You can select/retrieve:-
1. All the data from the table using *
2. A single column
3. Multiple columns
1️⃣ Select all columns of the table

SELECT * from table_name;

πŸ‘‰ E.g., Selecting/Retrieving all the values from the classroom1 table.

2️⃣ Select one column from the table

SELECT column_name from table_name;

πŸ‘‰ E.g., Selecting the student_name column from the table classroom1. Retrieving ALL the columns ...Retrieving ONE column from ...
Read 5 tweets
6 Jun
SQL is the most wanted skill in Data Science!! 😱

A Beginner's Guide to MySQL basic queries - Part 3!! 😎

Making mistakes while creating tables is common. Let's learn how to update and fix them! 😬

Thread 🧡
βœ… UPDATE THE TABLE

1. Add a column to the existing table:-

ALTER table table_name ADD (column_name datatype);

(Note: Adding a constraint to a column is optional)

πŸ‘‰ E.g., Adding the ADDRESS column to the classroom1 table. Addition of a new column to the table classroom1
2. Add MULTIPLE columns at once:-

ALTER table table_name ADD (colname1 datatype1, colname2 datatype2);

πŸ‘‰ E.g., Adding Email_id and ContactNo columns to the classroom1 table Adding multiple columns at once in classroom1 table.
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(