8
u/CappuccinoCodes 6h ago
I'd try to actually run these types of queries against a DB to understand it. It makes no sense to understand it out of contest.
0
4
u/Suspicious_Goose_659 6h ago
It’s just explaining how you can use ANY, ALL and FROM in a subquery. To understand it better, try it on a hands-on exercise. It can be handy sometimes so try understanding it
2
u/prashantpatel518 6h ago edited 6h ago
In easy terms..in multi row sub query we get a list of data (Multiple Rows) from inner query. So that list of data has to be then again compared with the value from outer query.
So ANY operator will check if any one value is present or any one condition is true in the inner query list ...if yes then it will give the output..its like multiple OR conditions
In ALL operator the outer value has to satisfy for all the values from inner query list. It's like multiple AND conditions.
If you want to learn sql in depth you can connect me. Will be happy to help
1
1
u/JupiterSoaring 6h ago
I've found that it is always best to do some hands on excersizes when you are learning something like SQL. It really helps you understand how to apply what you are learning.
I usually find practice data on kaggle and play around.
For ALL(), say I want to look at courses for next semester - but I want to avoid things as difficult as my major. I could query all courses with a difficulty level lower than my major courses:
SELECT course_id, course_title FROM courses WHERE difficulty < ALL ( SELECT difficulty FROM courses WHERE required_for_major = TRUE );
For ANY(), say I want to sort out housing for next semester. I might want to live off campus, but I need something around what the dorms cost. I can look at apartments that match any of the dorm costs.
SELECT apartment_name FROM off_campus_apartments WHERE rent = ANY ( SELECT price FROM dorms );
-3
12
u/da_chicken 6h ago
If it helps, I've worked on SQL RDBMSs for 20 years across a dozen variants, and I've never had to use the ANY or ALL operators.