A Beginner-friendly version of SQL (UPDATE and DELETE)
π§΅π
π Let's look at the table first!
The name of the table is -> faculties
We have columns as FacultyId, Name, Class, EmailId and Salary.
βοΈ UPDATE
This clause is used to change values in a specified column.
You may or may not provide a condition along with the change you want to make.
π Update without condition:-
UPDATE table_name SET column_name = column_value;
Query: Change the salaries of the faculties to 4000.
SQL Query: UPDATE faculties SET Salary = 4000;
O/P: All the values in the Salary Column would change to 4000.
π Update with a condition:-
UPDATE table_name SET column_name = column_value where CONDITION;
Query: Change the value of Salary to 2000 where the FacultyId is 103.
βοΈ DELETE
The DELETE clause would help you remove the row(s) from the table.
You have to specify a condition to delete a specific row.
*Important Note*: If you do not specify a condition within the DELETE clause, all rows would be deleted.
π Delete with the condition:-
DELETE from table_name where CONDITION;
Query: Delete the values from the Faculties table where the salary is 2000.
SQL Query: DELETE from faculties where Salary = 2000;
O/P: The row where the Salary is 2000 is deleted from the table.
π Delete all rows:-
TRUNCATE table_name;
With TRUNCATE, the table will exist in the database, but all the rows in that table will be deleted.
π To Delete a table from the database:-
DROP table table_name;
π To Delete a database:-
DROP database database_name;
FYI, I wanted to put this thread yesterday, but somehow I was unable to access my Twitter Web. Even now, I had to login via Incognito Mode.
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
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 π
βοΈ 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')
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
βοΈ 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;
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
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]