CYBER WEEK - EXTRA SAVINGS EVENT
TRY A FREE LESSON

SQL - Combining Rows Using Intersect and Except

Hello everyone :slight_smile:,

Why on this mission:

https://app.dataquest.io/m/190/building-and-organizing-complex-queries/6/combining-rows-using-intersect-and-except

I write the following code:

WITH 'inter' AS 
    (
     SELECT * FROM customer_usa

     INTERSECT

     SELECT * FROM customer_gt_90_dollars
    )
    
SELECT 
    e.first_name|| '  ' || e.last_name 'employee_name',
    COUNT(inter_e.customer_id) 'customers_usa_gt_90'
FROM employee 'e'
LEFT JOIN inter 'inter_e' ON inter_e.support_rep_id = e.employee_id
GROUP BY employee_name
HAVING e.title = 'Sales Support Agent'
ORDER BY employee_name;

And the result is: ‘The value for result doesn’t look right.’, although the value/result is right!!
I checked it running the answer in the solution and the resuld is exactly the same as with my code. First I thought it could be because I am not using the WHERE clause but the HAVING. Changing it resulted in the same outcome: ‘The value for result doesn’t look right.’
Then I changed the name of the subquery to the same as the on the in the answer ‘customers_usa_gt_90’ but the result was still the same: ‘The value for result doesn’t look right.’

I only get the validation once I copy paste the answer proposed in the exercise! Why is that when my produces exactly the same result, exactly the same table?!?

Thanks for your help :slight_smile:

I did some modification in you code, ie, removed the quotes from the inter and also replaced the single quotes in the concatenation of first_name and last_name and everything works fine

WITH inter AS 
    (
     SELECT * FROM customer_usa

     INTERSECT

     SELECT * FROM customer_gt_90_dollars
    )
    
SELECT 
    e.first_name|| " " || e.last_name employee_name,
    COUNT(inter_e.customer_id) customers_usa_gt_90
FROM employee e
LEFT JOIN inter inter_e ON inter_e.support_rep_id = e.employee_id
GROUP BY employee_name
HAVING e.title = 'Sales Support Agent'
ORDER BY employee_name;

Why did i do that?


2. Sqlite Quoting here
1 Like

Hehe, funny :smiley:

But why is that, @info.victoromondi? I read that the single quotes should not be a problem, and that’s what I’ve been using, and not a problem until here… :slight_smile:

I’m not using Backticks but single quotes…

Thanks!

Regards.