Can't see the top sql because it keeps flipping over, WTF.
Where are these examples?
Where are these examples?
SELECT
first_name,
last_name,
(
SELECT MAX(order_total)
FROM orders
WHERE customer.id = orders.customer_id
) AS maximum_order
FROM customers;
There's this one to get the maximum order amount for each customer that struck me, and another similar one.Instead of doing a JOIN they do this weird subquery. You can clearly see that it's the work of an AI and how this AI works (putting together lego pieces which are subqueries), because nobody would be writing this query like that.
1- e.g as Jamie explains here https://www.scattered-thoughts.net/writing/materialize-decor...
with toporders as (
select max(order_total) as maxOT, customer_id
from orders
group by customer_id
)
select last_name, maxOT
from customers join toporders
on ...
What would you suggest? SELECT
customer.first_name,
customer.last_name,
max(order.order_total) as maximum_order
FROM
customers customer
INNER JOIN
orders order
ON (customer.id = order.customer_id)
GROUP BY
customer.id