When to Use a Subquery in SQL

  Рет қаралды 37,063

Database Star

Database Star

Күн бұрын

Пікірлер: 71
@DatabaseStar
@DatabaseStar Күн бұрын
Want to easily remember the SQL commands for your database? Get my free SQL Cheat Sheets here: www.databasestar.com/get-sql-cheat-sheets/?
@willenaraines4596
@willenaraines4596 Жыл бұрын
You are the only person that has clearly explained why and how a subquery is used. I couldn't figure out what the benefits would be. Thank you!
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks for the feedback, glad you found it useful!
@adebanjomoyosore5721
@adebanjomoyosore5721 Жыл бұрын
Honestly, I have often wondered why we needed subqueries and nobody has explained it to me perfectly like this.
@Pandodora
@Pandodora Жыл бұрын
been traumatized by how complicated subquery is until I found your video. Very clear, straightforward and most importantly you explain such complicated query easily, that is indeed helpful, thanks!
@DatabaseStar
@DatabaseStar Жыл бұрын
I’m so glad that this video was helpful for you! Subqueries can be hard to understand
@buraktiras93
@buraktiras93 2 жыл бұрын
Your videos are extremely helpful. Clean and clear. Thanks for the content, waiting for more SQL videos!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks Burak, glad you like the videos!
@Nikopup
@Nikopup Жыл бұрын
The tips on breaking it down into simple steps and then bringing it all together really helps me a lot! Thank you ❤
@DatabaseStar
@DatabaseStar Жыл бұрын
You’re welcome! Glad this process was helpful.
@normn0
@normn0 9 ай бұрын
Excellent video. As someone from a different STEM industry, its amazing how much trash you need to sift through on KZbin to find something like this in programming.
@DatabaseStar
@DatabaseStar 9 ай бұрын
Thanks a lot! I'm glad you find my video is one of the good ones!
@zcecmsh99
@zcecmsh99 9 ай бұрын
You make the best SQL videos on the internet, thank you for making this so clear and concise - keep up the great work!
@DatabaseStar
@DatabaseStar 9 ай бұрын
Thanks a lot! I'm glad you like the video, I've been trying to make each video a little better than the last.
@nathan.bradley
@nathan.bradley Жыл бұрын
Thank you for helping me finally getting this. The way you broke it down made it so much easier to understand. Thanks again!
@DatabaseStar
@DatabaseStar Жыл бұрын
Glad it helped!
@ASharonOkech
@ASharonOkech 2 ай бұрын
This helped me understand subquery. I couldn't understand subquery before this video.
@DatabaseStar
@DatabaseStar 2 ай бұрын
Glad to hear it helped you understand it!
@adrianmora4481
@adrianmora4481 Жыл бұрын
This is great!! for the longest time, I was looking a logical explanation for subqueries
@DatabaseStar
@DatabaseStar Жыл бұрын
Glad it was helpful!
@dhairyapanjwani1456
@dhairyapanjwani1456 11 ай бұрын
finally cleared all the doubts in mind and got to know the mistake i was making!!!! Thank you for this video, amazing!
@DatabaseStar
@DatabaseStar 11 ай бұрын
Glad it was helpful!
@marie-sanna
@marie-sanna 4 ай бұрын
Thank you for taking the time to actually explain WHY we need the goddamn subqueries; they seemed useless for me but now I'm starting to understand their importance and relevancy, and your video was super helpful for this.
@DatabaseStar
@DatabaseStar 4 ай бұрын
Thanks! I tried to explain the "why": I've seen a lot of tutorials on this and they just explain the "how", but not why to use them.
@GmD.28
@GmD.28 4 ай бұрын
Thank you so much ! I’ve been finding it hard to get my head around this topic
@DatabaseStar
@DatabaseStar 4 ай бұрын
Glad it was helpful!
@Heli-b9s
@Heli-b9s 2 ай бұрын
Very well explained, thank you!
@DatabaseStar
@DatabaseStar 2 ай бұрын
Glad it was helpful!
@douaz6905
@douaz6905 2 ай бұрын
That was really helpful !
@DatabaseStar
@DatabaseStar 2 ай бұрын
Glad it helped!
@jwsc9578
@jwsc9578 Жыл бұрын
So well explained❤
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks!
@arunareddy3491
@arunareddy3491 2 жыл бұрын
Clear explanation
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks!
@dawitworku821
@dawitworku821 7 ай бұрын
Very helpful. Than you.
@DatabaseStar
@DatabaseStar 7 ай бұрын
Glad it helped!
@MultiGrapewine
@MultiGrapewine 2 жыл бұрын
I was confused why to use subquery when we can achieve same result set from joins. now it is clear
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it was helpful!
@mostafa2199
@mostafa2199 2 жыл бұрын
thanks man it really helped
@DatabaseStar
@DatabaseStar 2 жыл бұрын
No problem!
@olufemiolawale3848
@olufemiolawale3848 Жыл бұрын
Thank you sir.
@DatabaseStar
@DatabaseStar Жыл бұрын
You're welcome
@utkarshgupta6091
@utkarshgupta6091 2 жыл бұрын
hello. could u please cover some topics of sql that are required for data science like window functions. These topics were not present in your udemy course. please it would be of great help
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Great idea! I can do some videos on those.
@utkarshgupta6091
@utkarshgupta6091 2 жыл бұрын
@@DatabaseStar thank u. Would be of great help
@user-yh9vd9yz9u
@user-yh9vd9yz9u Жыл бұрын
Thank you!
@DatabaseStar
@DatabaseStar Жыл бұрын
You're welcome!
@tempMahad
@tempMahad 2 жыл бұрын
Hello, I got a question. I'm building a system for my organisation and this is what they do. They sell products which have varying prices depending on quantity. For example prestige 1kg is 130 but prestige box 10kg is 1,050. Please help me on how to create a database that can help with variations. Thanks
@DatabaseStar
@DatabaseStar 2 жыл бұрын
You might find my video on "eCommerce Database Design" helpful, which caters for products that can have variations like this.
@Manisha70856
@Manisha70856 Жыл бұрын
Select product_name from products where price > avg(price). Could you please confirm that can we write like this to find all the products having price greater than avg if products
@DatabaseStar
@DatabaseStar Жыл бұрын
Unfortunately that query won't work, but it makes sense and it would be helpful if it worked that way! The WHERE clause can't compare a value for a row against the result of an aggregate function like this. However, you can use a subquery like in this video to write it, to calculate the AVG in a subquery: Select product_name from products where price > (SELECT avg(price) FROM products);
@Pankaj-Verma-
@Pankaj-Verma- 9 ай бұрын
Thanks.
@DatabaseStar
@DatabaseStar 9 ай бұрын
You're welcome
@X1SX
@X1SX 2 жыл бұрын
Thank you
@DatabaseStar
@DatabaseStar 2 жыл бұрын
You’re welcome!
@icecube8496
@icecube8496 Жыл бұрын
Hi. Are you left handed? Just curious.
@DatabaseStar
@DatabaseStar Жыл бұрын
No, right handed actually. Is there something in the video that makes it seem like I am left handed?
@d_lydian
@d_lydian 2 жыл бұрын
Hey there, I've got a question: I got a signals table with 2 columns (ParameterID & Time). Everytime a Parameter gets updated, it gets a new timestamp, so there are a lot of database row entries with the same ParameterID and a different timestamp. I want to query the latest timestamp of 3 specific ParameterIDs (33200, 33201, 33202). How can I achieve that in Microsoft SQL? Thanks for your help!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
You could what's called a "correlated subquery" for this. You would use the subquery to find the maximum/latest timestamp for each of the parameter IDs, and then select the row that matches. Here's a query that could work: SELECT t1.parameter_id, t1.timestamp FROM your_table t1 WHERE t1.parameter_id IN (33200, 33201, 33202) AND t1.timestamp = ( SELECT MAX(timestamp) FROM your_table t2 WHERE t2.parameter_id = t1.parameter_id ); You could also use window functions to find the max values, which I've written about here: www.databasestar.com/select-rows-with-max-value/
@gggeeh
@gggeeh 2 жыл бұрын
hi thank you for your video, can i ask why is a subquery need in this practice solution: SELECT emp_no, (SELECT MIN(dept_no) FROM dept_emp de WHERE e.emp_no = de.emp_no) dept_no, FROM employees e; Was wondering why I cannot use join like this instead: SELECT e.emp_no, MIN (de.dept_no) as dept_no, FROM employees e JOIN dept_emp de ON e.emp_no = de.emp_no;
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Both queries should show the same results so I don't see how the first one needs to use a subquery. The second query will actually return an error as it does not have a GROUP BY, but once you add GROUP BY e.emp_no, they should be the same. (I haven't tested these queries so I could be wrong)
@gggeeh
@gggeeh 2 жыл бұрын
@@DatabaseStar hey thanks for your reply, it helps!
@patientson
@patientson 11 күн бұрын
Bad teaching... teach the art of applying subquery to a table and two tables. No tip was helphul at at all.
@DatabaseStar
@DatabaseStar 11 күн бұрын
Thanks for the feedback! Is there a better way that you would explain it?
@adebanjomoyosore5721
@adebanjomoyosore5721 Жыл бұрын
Thank you!
@DatabaseStar
@DatabaseStar Жыл бұрын
You're welcome!
@nrk07
@nrk07 6 ай бұрын
Thank you
@DatabaseStar
@DatabaseStar 6 ай бұрын
You’re welcome
SQL Subquery | Complete Guide with Correlated Subquery | #SQL Course #15
1:21:28
Self Join in SQL
9:09
Database Star
Рет қаралды 48 М.
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 3,5 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН
7 Mistakes Beginners Make with SQL
10:47
Database Star
Рет қаралды 20 М.
SQL CTEs (Common Table Expressions) - Why and How to Use Them
7:56
Database Star
Рет қаралды 35 М.
7 Database Design Mistakes to Avoid (With Solutions)
11:29
Database Star
Рет қаралды 87 М.
Subqueries, HAVING, CASE... more advanced SQL concepts (tutorial for beginners in data science EP#5)
24:49
SQL Window Functions: Explained (with examples)
9:11
Database Star
Рет қаралды 34 М.
MySQL - The Basics // Learn SQL in 23 Easy Steps
17:17
Fireship
Рет қаралды 914 М.
SQL Joins: A Guide and Examples
11:38
Database Star
Рет қаралды 28 М.
Machine Learning for Everybody - Full Course
3:53:53
freeCodeCamp.org
Рет қаралды 8 МЛН
How to Solve This Database Design Problem
8:09
Database Star
Рет қаралды 3,6 М.