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 🙂
@hadibq2 жыл бұрын
same here! 👍 so useful
@kc123456789101112 Жыл бұрын
Finally, someone answered the nagging question in my head, "Why not just use a join?" Thanks Doug!
@adreamer99996 жыл бұрын
Thank you for the explanation. Very helpful.
@babybob88236 жыл бұрын
Very clear and to the point. Thanks a lot.
@bagindamirza Жыл бұрын
much thanks for your video! great explanation on this topic!
@gbting19885 жыл бұрын
Thx for the explanation. Do you mean exist will dedup and same with IN statement it will dedup too?
@DatabasebyDoug5 ай бұрын
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.
@hadibq2 жыл бұрын
Very nicely explained 👍TY
@voodoochili127 жыл бұрын
Great explanation, thank you
@z401401103 жыл бұрын
Thank you very much for such great content.
@MethodOverRide4 жыл бұрын
Fantastic video and exactly what I needed!
@DatabasebyDoug4 жыл бұрын
Glad it was helpful!
@r0cketRacoon11 ай бұрын
in subquey, can I select * or any random columns ? does it have to follow any patterns of select in subquery?
@DatabasebyDoug11 ай бұрын
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.
@r0cketRacoon11 ай бұрын
@@DatabasebyDoug tks u
@bruville5 жыл бұрын
Very good explanation! Thanks!
@aspanon15605 жыл бұрын
Thanks a lot. What does the query return if WHERE EXISTS returns false?
@DatabasebyDoug5 жыл бұрын
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.
@debayan898 жыл бұрын
It cleared my doubts. Very very helpful.
@hieptrinh23084 жыл бұрын
Thank you for making it understandable.
@Sonny02767 жыл бұрын
Great Video. Thank you for posting.
@VincenzoCorvaglia2 жыл бұрын
Very good explanation. Tank you so much!
@ИванКузнецов-ж3к7 жыл бұрын
Thanks for your lesson that's easy to understand.
@yeoshuabenzaken77368 ай бұрын
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?
@DatabasebyDoug5 ай бұрын
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!
@chethanprabhu44758 жыл бұрын
which software is that? ty
@DatabasebyDoug8 жыл бұрын
+Chethan Prabhu I'm using Microsoft SQL Server.
@sergeykurk7 жыл бұрын
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?
@ntuninerlo7 жыл бұрын
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
@dfence19859 жыл бұрын
Very useful and detailed. Thank you!
@VeronicaAngryPolak Жыл бұрын
this was awesome
@laurafosci5 жыл бұрын
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
@vaibhavkumar384 жыл бұрын
because of the use cases these keywords support
@Tgarth994 жыл бұрын
Good video!
@Tgarth994 жыл бұрын
Very clear!
@DatabasebyDoug4 жыл бұрын
Glad you think so!
@christianrodier33812 жыл бұрын
That is very helpful
@padminimurthy71608 жыл бұрын
Very nicely explained
@erlendstlie44317 жыл бұрын
Thanks, really helpful
@abdulsami19827 жыл бұрын
can we use where exists. or where not exists with insert query ?
@DatabasebyDoug6 жыл бұрын
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.