7 Mistakes Beginners Make with SQL

preview_player
Показать описание

Learning SQL can be hard with the number of places to learn from and the functionality of the language.

As you learn more and get more experienced, you realise some of the things you learned when you were a beginner weren’t the best way to do something.

But what if you're a beginner?

What are those things you should avoid?

In this video, I’ll explain 7 areas or mistakes that I see being made as a beginner, why they should be avoided, and what to do instead.

Timestamps:
00:00 What are we learning?
00:27 Mistake 1 - Using SELECT *
02:48 Mistake 2 - Writing one query per table
03:51 Mistake 3 - Not using functions
05:13 Mistake 4 - Using reserved words for table and column names
06:30 Mistake 5 - Not using WHERE with DELETE or UPDATE
08:17 Mistake 6 - Comparing with NULL using =
09:03 Mistake 7 - Not saving queries to use again
Рекомендации по теме
Комментарии
Автор

Your channel helped (and still) me a lot while learning SQL
Thanks man ♥️
Keep the good work up

mostafa
Автор

Another (IMO better) way to do #5 is just write it as a SELECT query to start. You need to validate your records before updating/deleting anyway. Once it's correct you can replace SELECT with DELETE; or write UPDATE/SET clause without the FROM and WHERE; and copy/paste the WHERE from the SELECT query. I often end up with something like this, and once my result set is what I want I flip the commenting from UPDATE to SELECT:

select COLA, COLB, COLC
from TBLA
--update TBLA
-- set COLA = x
-- , COLB = y
-- , COLC = z
where CRITERIA1
and CRITERIA2
etc...

angelbear_og
Автор

Hello sir. Are you planning to cover window functions like over-partition by clause and topics like cte? please consider the employee database that you used in your udemy course as it will be easier to understand from it. please cover these topics.

utkarshgupta
Автор

what command will reveal all the columns/attribute of a table without using "SELECT * FROM table" in order to avoid mistake n.1?

TheInternetFan
Автор

7:52 NO NO NO NO! YOU DO NOT RUN AN UPDATE OR DELETE CLAUSE WITHOUT CHECKING WITH SELECT FIRST!
REDO THIS ADIVE I BEG YOU! Write a SELECT statement and see if the returned data is truly what you wanted to mofiy. Then only then, replace SELECT with UPDATE OR DELETE.

tsunamio
Автор

The suggestion #2 is absolutely wrong and it may and certainly will cause your application to halt. Let's imagine a real application consisting of something like follows:
table Orders
(
OrderId primary key,
-- ~ 20 columns with data
)
table OrderItems
(
OrderId int reference to Order,
ProductId int reference to Product,
primary key (OrderId, ProductId)

-- ~ 8-10 other columns with data
)
table Products
(
ProductId primary key,

-- 10 other columns with data
)

Now, we need to fetch information about 10 orders with their items and products to construct business logic models. Let's assume that each order has 20 items. In case of one select query which joins all related tables and return one result we will have:
200 rows - 10 orders * 20 order items
each row consists of 40 fields - 20 field of order + 10 field of order item + 10 field of product
So that we will have 200 * 40 = 8000 values fetched from the db

if we execute three separate queries to receive the same data table by table, we will have:
10 * 20 = 200 values for orders
20 * 10 * 10 = 2000 values for order items
20 * 10 * 10 = 2000 values for products and it is only of all products are unique throughout all orders which is very rear case.
So that we will have 200 + 2000 + 2000 = 4200 and even less values fetched from the db.
And this difference grows very quickly as information from new tables are needed because they have to be joined to the one select statement.
The main problem of a join operation that it duplicates information in rows, this is the reason of difference in field count mentioned above. Moreover, one statement approach does not allow to use caches to reduce common amount of data needed from db.

romanpikulenko
Автор

*Mistake 3 - Not using functions*
4:17 "SQL includes many in-built functions to process data and give you a result."
Where is the *MEDIAN* function ????

andrewkamoha
Автор

Nothing wrong with using select * if you do not know all the columns in the table.
And to prevent getting to much data, just limit the rows with 'ROWNUM < 10' for example, or like 'fetch first 10 rows only'

luupski