The SQL EXISTS clause

  Рет қаралды 64,318

Database by Doug

Database by Doug

Күн бұрын

Пікірлер: 52
@vyvianspipes
@vyvianspipes 2 жыл бұрын
Doug, you have helped me tremendously! When the part about NOT EXISTS was explained, this in itself shed light onto the exact problem I needed to mitigate. Thank you 🙂
@hadibq
@hadibq 2 жыл бұрын
same here! 👍 so useful
@kc123456789101112
@kc123456789101112 Жыл бұрын
Finally, someone answered the nagging question in my head, "Why not just use a join?" Thanks Doug!
@adreamer9999
@adreamer9999 6 жыл бұрын
Thank you for the explanation. Very helpful.
@babybob8823
@babybob8823 6 жыл бұрын
Very clear and to the point. Thanks a lot.
@bagindamirza
@bagindamirza Жыл бұрын
much thanks for your video! great explanation on this topic!
@gbting1988
@gbting1988 5 жыл бұрын
Thx for the explanation. Do you mean exist will dedup and same with IN statement it will dedup too?
@DatabasebyDoug
@DatabasebyDoug 5 ай бұрын
That's an interesting way to look at it. Yes! EXISTS will avoid looking at duplicates once it finds one that matches. Similarly with IN. But, I'm not sure whether it *efficiently* finds the first match.
@hadibq
@hadibq 2 жыл бұрын
Very nicely explained 👍TY
@voodoochili12
@voodoochili12 7 жыл бұрын
Great explanation, thank you
@z40140110
@z40140110 3 жыл бұрын
Thank you very much for such great content.
@MethodOverRide
@MethodOverRide 4 жыл бұрын
Fantastic video and exactly what I needed!
@DatabasebyDoug
@DatabasebyDoug 4 жыл бұрын
Glad it was helpful!
@r0cketRacoon
@r0cketRacoon 11 ай бұрын
in subquey, can I select * or any random columns ? does it have to follow any patterns of select in subquery?
@DatabasebyDoug
@DatabasebyDoug 11 ай бұрын
Technically, you can use any column - EXISTS does not check any column values, only for the existence/nonexistence of a row. For code clarity, * is good because it is succinct and doesn't lead a reader of your code to think you have some other intention.
@r0cketRacoon
@r0cketRacoon 11 ай бұрын
@@DatabasebyDoug tks u
@bruville
@bruville 5 жыл бұрын
Very good explanation! Thanks!
@aspanon1560
@aspanon1560 5 жыл бұрын
Thanks a lot. What does the query return if WHERE EXISTS returns false?
@DatabasebyDoug
@DatabasebyDoug 5 жыл бұрын
Hi and thanks for the question. As with any WHERE clause, if the WHERE clause evaluates to false for a record, the record is not shown. So if WHERE EXISTS returns false for a record, that record is not shown. If WHERE EXISTS returns false for *every* record in the outer query, then there will be no records in the result.
@debayan89
@debayan89 8 жыл бұрын
It cleared my doubts. Very very helpful.
@hieptrinh2308
@hieptrinh2308 4 жыл бұрын
Thank you for making it understandable.
@Sonny0276
@Sonny0276 7 жыл бұрын
Great Video. Thank you for posting.
@VincenzoCorvaglia
@VincenzoCorvaglia 2 жыл бұрын
Very good explanation. Tank you so much!
@ИванКузнецов-ж3к
@ИванКузнецов-ж3к 7 жыл бұрын
Thanks for your lesson that's easy to understand.
@yeoshuabenzaken7736
@yeoshuabenzaken7736 8 ай бұрын
in the first example (select 17) the exists is acting like a Boolean since the subquery is true so it brings everything in the outer query but in the 2nd example (the correlated query) exists is acting like "in" . how is that?
@DatabasebyDoug
@DatabasebyDoug 5 ай бұрын
Sorry for the delayed response. You are right EXISTS is an operator that returns a boolean value. In the first "trivial" example, SELECT 17 always returns exactly one record, so EXISTS (SELECT 17) is always True. In the second example (correlated subquery), the subquery's results change based on a record in the outer query. So EXISTS() returns true or false, based on a record in the outer query, i.e., it is *correlated* with the outer query. You can phrase the same intended result using IN. In English, you could say "Categories where a Product exists in that category" or "Categories that are in a Category list drawn from the Products table". Both end up with the same result. I hope that helps!
@chethanprabhu4475
@chethanprabhu4475 8 жыл бұрын
which software is that? ty
@DatabasebyDoug
@DatabasebyDoug 8 жыл бұрын
+Chethan Prabhu I'm using Microsoft SQL Server.
@sergeykurk
@sergeykurk 7 жыл бұрын
i don't understand. in the first example we get ALL CategoryNames from Categories if there is at least one row in subquery ? or only CategoryNames that have products?
@ntuninerlo
@ntuninerlo 7 жыл бұрын
in the first statement the subquery is true, so the query returns all records. in the second, because of the correlated subquery, only individual records correlated with each true instance are returned. at least thats what i believe to be true
@dfence1985
@dfence1985 9 жыл бұрын
Very useful and detailed. Thank you!
@VeronicaAngryPolak
@VeronicaAngryPolak Жыл бұрын
this was awesome
@laurafosci
@laurafosci 5 жыл бұрын
May I ask you why Joins are more popular than the Exists clause? At least when I go to interviews or I speak to people they always ask me about Joins but never about the Exists clause
@vaibhavkumar38
@vaibhavkumar38 4 жыл бұрын
because of the use cases these keywords support
@Tgarth99
@Tgarth99 4 жыл бұрын
Good video!
@Tgarth99
@Tgarth99 4 жыл бұрын
Very clear!
@DatabasebyDoug
@DatabasebyDoug 4 жыл бұрын
Glad you think so!
@christianrodier3381
@christianrodier3381 2 жыл бұрын
That is very helpful
@padminimurthy7160
@padminimurthy7160 8 жыл бұрын
Very nicely explained
@erlendstlie4431
@erlendstlie4431 7 жыл бұрын
Thanks, really helpful
@abdulsami1982
@abdulsami1982 7 жыл бұрын
can we use where exists. or where not exists with insert query ?
@DatabasebyDoug
@DatabasebyDoug 6 жыл бұрын
Hi Abdul. Sounds like you want to insert a record only if it doesn't exist? You can use WHERE NOT EXISTS in the SELECT that creates the records to be inserted, and you can reference the same table you are inserting into in your SELECT. You might also take a look at the MERGE statement - it might do everything you want.
@denyskulpa6241
@denyskulpa6241 4 жыл бұрын
you the MAN!
@malekimilad4245
@malekimilad4245 6 жыл бұрын
Great, thanks man
@SuperAaronsun
@SuperAaronsun 3 жыл бұрын
love it
@semikolon4229
@semikolon4229 4 жыл бұрын
Thank you Sir.
@DatabasebyDoug
@DatabasebyDoug 4 жыл бұрын
You are most welcome
@oksanaveretiuk1653
@oksanaveretiuk1653 9 жыл бұрын
Thanks a lot!
@seanangeluasmolo1471
@seanangeluasmolo1471 2 жыл бұрын
exists are not for beginners xD
@Sinha.ritesh
@Sinha.ritesh 7 жыл бұрын
thanks 😃
The SQL INSERT statement
11:58
Database by Doug
Рет қаралды 1,3 М.
Simple Recursion in SQL
15:15
Database by Doug
Рет қаралды 95 М.
бабл ти гель для душа // Eva mash
01:00
EVA mash
Рет қаралды 7 МЛН
How Strong is Tin Foil? 💪
00:25
Brianna
Рет қаралды 64 МЛН
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 2,6 МЛН
EXIST Function in SQL
8:04
Edredo for Learners
Рет қаралды 122 М.
SQL Subquery using EXISTS and IN - SQL Tutorial #31
10:13
Data with Baraa
Рет қаралды 2,2 М.
When to Use a Subquery in SQL
8:50
Database Star
Рет қаралды 36 М.
SQL | NOT IN Vs NOT EXISTS (Which one to use?)
10:03
Learn at Knowstar
Рет қаралды 11 М.
Using the IN Operator in SQL
8:25
Database by Doug
Рет қаралды 12 М.
SQL Tutorial #13 - SQL EXISTS and NOT EXISTS Operator
9:42
Software Testing Mentor
Рет қаралды 40 М.
59 Exists operator in SQL Server
12:50
Learn SSIS
Рет қаралды 1,5 М.
How to use the SQL EXISTS and NOT EXISTS conditional operators
6:01
SQL EXISTS VE NOT EXISTS KULLANIMI
5:49
gracia heys
Рет қаралды 2 М.
бабл ти гель для душа // Eva mash
01:00
EVA mash
Рет қаралды 7 МЛН