MySQL: SUBQUERIES

MySQL: SUBQUERIES

Bro Code

1 год назад

83,188 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Bro Code
Bro Code - 12.11.2022 00:25

SELECT first_name, last_name, hourly_pay,
(SELECT AVG(hourly_pay) FROM employees) AS avg_pay
FROM employees;

SELECT first_name, last_name
FROM employees
WHERE hourly_pay > (SELECT AVG(hourly_pay) FROM employees);

SELECT first_name, last_name
FROM customers
WHERE customer_id IN (SELECT DISTINCT customer_id
FROM transactions WHERE customer_id IS NOT NULL);

SELECT first_name, last_name
FROM customers
WHERE customer_id NOT IN (SELECT DISTINCT customer_id
FROM transactions WHERE customer_id IS NOT NULL);

Ответить
Abdallah Mohamed
Abdallah Mohamed - 04.11.2023 11:11

🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩

Ответить
Nockin
Nockin - 29.10.2023 19:28

Thank you from Chile

Ответить
Kristijan Lazarev
Kristijan Lazarev - 29.10.2023 10:24

godlike

Ответить
Ariel Espindola
Ariel Espindola - 22.10.2023 05:22

I think you should touch on the performance too! These subqueries can be costly and suck up CPU in large tables. In the first example, the average was computed per row while $14.35 was needed only once. Other than that, great video. Thanks!

Ответить
Thato Tman
Thato Tman - 10.10.2023 16:53

your videos are so concise!!!! Niceeeee

Ответить
Amit Patel
Amit Patel - 28.09.2023 02:49

Bro code explains coding beautifully, but specifically for SQL I think "techtfq" channel is my personal favourite...

Ответить
Jing
Jing - 22.09.2023 22:50

ok i was pretty frustrated until i started this video hearing Bro Code calling the manager as "Krabs" or craps? is this intentional? Bor Code is my type!

Ответить
Hassan
Hassan - 23.08.2023 23:25

You are the bestttttttttttt❤❤❤

Ответить
Harrison Miles
Harrison Miles - 16.08.2023 08:33

What about subqueries inside FROM?

Ответить
Ross Williams
Ross Williams - 13.08.2023 02:33

love you bro

Ответить
Adebanke Bamidele
Adebanke Bamidele - 11.08.2023 07:36

I finally got to understand this topic. This was amazing.
Kudos and Bravos😂

Ответить
Sivuyile Sifuba
Sivuyile Sifuba - 10.08.2023 20:05

Ответить
Samuel Magana
Samuel Magana - 10.08.2023 11:57

Or you can use a window function

Ответить
Daggen
Daggen - 03.08.2023 01:43

After so many wrong and complicated examples on this topic finally a good and clear explanation, it helped me thanks.

Ответить
MathiasDC
MathiasDC - 16.07.2023 15:25

I'm not sure if someone could answer this but I'll try:

SELECT first_name, last_name, hourly_pay
FROM employees
WHERE hourly_pay > (SELECT AVG(hourly_pay) FROM employees);

In this query, why can't we just, after the "greater than", write "AVG(hourly_pay)" ??

Ответить
DiyAsianGuy
DiyAsianGuy - 30.06.2023 22:45

Excellent tutorial!

Ответить
pabitra kb
pabitra kb - 30.06.2023 10:15

Great explanation
Thank you ☺️

Ответить
Alien3.0C
Alien3.0C - 04.06.2023 19:34

Thanks, well explained

Ответить
Damian Kadziela
Damian Kadziela - 31.05.2023 11:41

The customer and transactions example would be normally done with JOIN:
SELECT DISTINCT first_name, last_name FROM customers
JOIN transactions ON customers.customer_id = transactions.customer_id;
it's a bit shorter query, but it's cool to see that you can do this with other methods as well.

Ответить
Marcus Seth Elric
Marcus Seth Elric - 20.04.2023 12:30

This looks like a nested "if" and "loop" statements in Java. I wouldn't be learning those without your tutorials in Java. And I know I will be learning those further when I start learning the other prog. languages you have on your playlist.

Thank you so much!

Ответить