EXIST Function in SQL

  Рет қаралды 123,688

Edredo for Learners

Edredo for Learners

Күн бұрын

Пікірлер: 77
@lowkeygo
@lowkeygo 11 ай бұрын
I struggled because I did not understand the logic of how outer query recognizes the conditions in the where clause of the subquery. So this has helped me understanding the concept: 1. First look at the outer query and think it as "Each row is about to be returned!" 2. But in order for a row to be returned, "where exists" clause must be true. 3. Now we look at the where clause inside the subquery. Here, usually we make outerquery.id = subquery.id because "we are determining whether the current row should be returned or not". And this current row has its own id. Furthermore, usually, you put 1 more condition such as subquery.quantity > 2. 4. Now, the subquery will look for the id that is about to be returned in the outer query inside the subquery, and see if there's any row that meets the second condition (quantity >2). 5. If there's any row that matches the condition inside the subquery, outer query can return the current row. Otherwise, it skips and the same process repeats for the next row.
@mathemagic516
@mathemagic516 27 күн бұрын
Thank you so much!
@brontesaurus1
@brontesaurus1 5 жыл бұрын
Thank you! I have struggled with this for a while. No one (teacher nor book) ever emphasized that the outer query would or would not run based on the subquery.
@luke6350
@luke6350 4 жыл бұрын
same with me. glad i found this video
@captoori
@captoori 3 жыл бұрын
Same here. Others teach like it was obvious
@KatRollo
@KatRollo 3 жыл бұрын
Difference of an effective teacher :)
@trollanddrump5326
@trollanddrump5326 4 жыл бұрын
How can you forget SEX? Unbelievable!
@sujaysshenoy247
@sujaysshenoy247 5 жыл бұрын
super clear explaination of the exists concept, i was struggling to understand this concept Thank you!!
@oscarv6907
@oscarv6907 2 жыл бұрын
You explained it so well, thank you so much!
@lorraineliu8422
@lorraineliu8422 6 жыл бұрын
Very clear. Thank your for the instruction!
@Avict-18
@Avict-18 6 ай бұрын
Thank you very much, I had been struggling with this for quite a while now I guess you are the one that has explained it the best> I was wondering how the outer query has recognized the condition of the inner query but now i get it
@tanishktripathi8773
@tanishktripathi8773 4 жыл бұрын
Doubts cleared at a time immense need ♥️
@stephenokon3227
@stephenokon3227 3 жыл бұрын
Thank you so much for this video. You demystified this concept in-toto! I appreciate you.
@angelthedecentgirl7181
@angelthedecentgirl7181 3 жыл бұрын
Thank You so much sir, i have been searching for a good video for the long time, and i finally discovered this. It is actually6 fruitful for me.
@ŁukaszSmykał
@ŁukaszSmykał Жыл бұрын
obvious but super helpful thanks to You I bypass my problem in BigQuery :) thx:)
@amirtaghavy7647
@amirtaghavy7647 3 жыл бұрын
What is the advantage of using EXIST func in your example over setting up the query like: SELECT * FROM professor WHERE eid IN (SELECT adviser FROM student WHERE sex = 'F'); ??
@hechbkee2220
@hechbkee2220 2 жыл бұрын
Is this an alternative?
@rss1322
@rss1322 2 жыл бұрын
IN returns an array. EXIST returns a simple TRUE or FALSE. So EXIST is more efficient in this particular example. But you cannot EXIST where you need the entire array of employee ids as an output.
@hechbkee2220
@hechbkee2220 2 жыл бұрын
Thank you very much for your lesson..Looks easy but I do not know why I am finding it difficult
@gaborszepes8107
@gaborszepes8107 8 жыл бұрын
Dear Sir, I guess "EXIST" is actually "EXISTS"... I am a beginner in this field this is the reason why I am asking. Thank You for your answer in advance. Best regards, G.Sz.
@Edredo
@Edredo 8 жыл бұрын
+Gábor Szepes You are absolutely correct. The video should be improved ASAP
@r0cketRacoon
@r0cketRacoon Жыл бұрын
is it compulsory to select ROLLNO in subquey, can I select * or any random columns ? do it have to follow any patterns of select in subquery?
@sandeepagri2218
@sandeepagri2218 4 жыл бұрын
Are you writing with mouse...!!! Coz your onscreen writing is so clear and flawless
@shadaflorida4248
@shadaflorida4248 4 жыл бұрын
Amazing explanation! Thank you so much!
@sthk1998
@sthk1998 4 жыл бұрын
What if I want Professers with at least 2 female students? Do I do a groupby prof, count >=2 in the internal query?
@siddharthasharma9316
@siddharthasharma9316 3 жыл бұрын
he uses at least one for the EXISTS function however if such a scenario happens then we use groupby clause along with the Having Clause for conditions.
@sidharthmandal9957
@sidharthmandal9957 2 жыл бұрын
atleast 1 means:- 1 or more than 1 (i guess we need to use this in inner query using group by and having ) The video explained answer is:- find out the name of professor who has female student ! correct me if im wrong !
@vasanthavasu8696
@vasanthavasu8696 3 жыл бұрын
Use of exists function is cleared. But we can write sub queries instead of this. That will be easy to write. Then what is the purpose of using exists. Can anybody clarify on this
@zhijieshi692
@zhijieshi692 7 ай бұрын
will there be any value returned if only the inner query is executed? (ignore the exist, outer query)
@unnikrishnanvannadil
@unnikrishnanvannadil 3 жыл бұрын
How is this different from using IN ? In the above example wouldn't IN be a better option and take care of the same logic?
@pradeepkumar.5172
@pradeepkumar.5172 4 жыл бұрын
thank u so much.........i understood this concept now.
@nikolasioakimidis3003
@nikolasioakimidis3003 2 жыл бұрын
Thanks mate, that's actually a good vid
@VanBhardwaj
@VanBhardwaj 5 жыл бұрын
Are the results produced by replacing "exists" with "not exists" in a query always mutually exclusive?
@nickyevdokymov5526
@nickyevdokymov5526 Жыл бұрын
All the best coding tutorials on KZbin are made with Indian accent, lol. Thank from Ukraine, btw
@Renegade_rm56
@Renegade_rm56 3 жыл бұрын
Really nice handwriting ;)
@SamChan-p4j
@SamChan-p4j 6 күн бұрын
what if the condition changes to "for at least 2 female students" ?
@MarceloAgostonSchrotlin
@MarceloAgostonSchrotlin 4 жыл бұрын
THANNKSS A LOOOOOOOOOOT!!! YOU SAVE MY LIFE DUDE!!
@prernasemwal3016
@prernasemwal3016 3 жыл бұрын
Sir why arent we using join in the inner query as two tablesare being joined
@muhammadkemalghifarirais4470
@muhammadkemalghifarirais4470 4 жыл бұрын
THANNNKS YOU ARE THE BEST!
@caitancorreia8379
@caitancorreia8379 8 жыл бұрын
A question sir, What would happen if instead of P.Eid =S. Advisor we just say Eid=Advisor without renaming as P and as S. What would happen then? Is that wrong?
@sukantasen1
@sukantasen1 8 жыл бұрын
It will work s well as EID and Advisor are different column name but having same datatype and you will get the same result
@pallavi4501
@pallavi4501 7 жыл бұрын
Sukanta Sen ya correct
@lordmefisto255
@lordmefisto255 6 жыл бұрын
U should use Professor.Eid=Student.Advisor because ( P is for Professor table and S is for student)
@superfreiheit1
@superfreiheit1 3 жыл бұрын
Exists: IF Subquery is empty, then not execute outer-query
@juniorocana7171
@juniorocana7171 Жыл бұрын
Thanks!
@sureshk1099
@sureshk1099 2 жыл бұрын
thank you
@jackdaniel1579
@jackdaniel1579 7 жыл бұрын
Can this whole Exist can be used with IN?
@ahmedelshenawy6357
@ahmedelshenawy6357 Жыл бұрын
Thanks..
@codestorywithMIK
@codestorywithMIK 7 жыл бұрын
very well explained
@nicofrancisco3216
@nicofrancisco3216 2 жыл бұрын
thank u very helpful
@lokeshphoenix
@lokeshphoenix 6 жыл бұрын
can we write select name , AVG(sal) from employee group by department having sal>AVG(sal) ??
@lordmefisto255
@lordmefisto255 6 жыл бұрын
of course ;)
@Ebiru2387
@Ebiru2387 4 жыл бұрын
I have a question. A colleague wrote averysimilarly structured query, except in the subquery instead of writing "Select RollNo From....", they wrote "Select 1 From". Could one speculate this was done for efficiency? Or Could you provide your thoughts why this might be? I commonly see "Select 1" and "EXISTS" together quite frequently and am curious why it is used.
@archidar1
@archidar1 4 жыл бұрын
You only need the table after the EXISTS clause to exist (i.e. contain any value). The value itself does not matter. Hence, you can use SELECT 1 ... to save time, or show that you do not care about the value.
@praveenpalina6591
@praveenpalina6591 7 жыл бұрын
Hi sir, Which one fast exists or in?why?
@yashmishra12
@yashmishra12 3 жыл бұрын
"In" is faster because the outer query is run once while in EXISTS, the outer query is run for each inner query element.
@maheshmenta6078
@maheshmenta6078 8 ай бұрын
thank u
@vohuuthang7217
@vohuuthang7217 2 ай бұрын
great
@azra8366
@azra8366 4 жыл бұрын
Thank you sir, that was helpful :)
@p.m8042
@p.m8042 6 жыл бұрын
Are you the guy who made coding school series?
@muhammadsafiullah8428
@muhammadsafiullah8428 5 жыл бұрын
No
@wordsthatcount8077
@wordsthatcount8077 Жыл бұрын
thank
@adaseth
@adaseth 8 жыл бұрын
#ASMR ;)
@ericzheng4815
@ericzheng4815 2 жыл бұрын
It's EXIST or EXISTS? I'm confused rn
@MiauMichigan
@MiauMichigan 2 жыл бұрын
With 'S'
@jordan5253
@jordan5253 5 жыл бұрын
okay
@wajdihammami7452
@wajdihammami7452 4 жыл бұрын
fking genius
@hemantkilanje8865
@hemantkilanje8865 4 жыл бұрын
I didnt understand
@dude789d
@dude789d 3 жыл бұрын
Atleast do your homework first...its existS not Exist...plural...
@ofek5365
@ofek5365 5 жыл бұрын
Thank you And thank god for Google Auto Generated Subtitles
@ProcessOverProfitHQ
@ProcessOverProfitHQ 3 жыл бұрын
Sexuality and Gender are not same
@tobicipher9300
@tobicipher9300 3 жыл бұрын
Gender and sex are the same, however, what we call sexuality these days are nothing more than fetishes people identify with.
@mariasilverdale6444
@mariasilverdale6444 2 жыл бұрын
Thank you
@vaibhavmehta3424
@vaibhavmehta3424 3 жыл бұрын
okay
Understanding Correlated Queries in SQL
8:13
Edredo for Learners
Рет қаралды 142 М.
Understanding Set Comparison Operator in SQL
11:15
Edredo for Learners
Рет қаралды 36 М.
SQL Tutorial #13 - SQL EXISTS and NOT EXISTS Operator
9:42
Software Testing Mentor
Рет қаралды 41 М.
SQL "difference between" interview questions (part 1)
8:20
Crack Concepts
Рет қаралды 633 М.
The SQL EXISTS clause
8:52
Database by Doug
Рет қаралды 64 М.
SQL | NOT IN Vs NOT EXISTS (Which one to use?)
10:03
Learn at Knowstar
Рет қаралды 12 М.
We Learn SQL #14 | Correlated subqueries with EXISTS in SQL
3:46
We Learn SQL
Рет қаралды 13 М.
Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF
28:34
Decomplexify
Рет қаралды 2,1 МЛН
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 217 М.
Advanced Aggregate Functions in SQL (GROUP BY, HAVING vs. WHERE)
6:00
Becoming a Data Scientist
Рет қаралды 267 М.
How to use the SQL EXISTS and NOT EXISTS conditional operators
6:01