SQL Syntax problem

Hey guys I have one question, I am doing this exercise in SQL course and I guess I have problem with syntax. Basicaly I wrote this code :

SELECT 
  DISTINCT quiz.user_id,
  home_try_on.user_id IS NOT NULL AS 'Is home try on',
  home_try_on.nuber_of_pairs,
  purchase.user_id IS NOT NULL AS 'Is purchase'
FROM quiz
LEFT JOIN home_try_on
  ON quiz.user_id = home_try_on.user_id
LEFT JOIN purchase
  ON purchse.user_id = quiz.user_id
LIMIT 10;

And the correct solution provided by codecademy is :

SELECT DISTINCT q.user_id,
   h.user_id IS NOT NULL AS 'is_home_try_on',
   h.number_of_pairs,
   p.user_id IS NOT NULL AS 'is_purchase'
FROM quiz q
LEFT JOIN home_try_on h
   ON q.user_id = h.user_id
LEFT JOIN purchase p
   ON p.user_id = q.user_id
LIMIT 10;

Mine is not working. But I do not get any error message from codecademy and I do not know why. I have just blank white screen as if I did not ever run the code. I guess I have something wrong with my code. Do you have an idea what went wrong from my side?

Thanks

While there is’nt enough information to tell for sure:

AS 'Is home try on' and 'Is purchase' are a bit of a no-no in SQL. It may not always throw a tangible error, but it is considered bad form to write spaces in column names (aside from it being non-standard, it makes selecting them harder later, and can create other sets of problems).

Now, I don’t know that it’s considered something that will throw an error, but I can see why the Codecademy workspace would not accept it as valid.

On the bigger note of errors, I think they’re a little thin on specificity in the SQL lessons. Take it as an opportunity to learn how to trouble-shoot really well. If you want to get a more specific error, try making mock examples of the db (the same columns and only a few rows) on sqlite3 or DB Browser. At least then you’ll know whether the code runs in a real environment, and the code you wrote in the lesson is just missing the required parameters for said lesson.

1 Like

Thank you for your time and answer. But I removed spaces between words and the same problem is still occuring. To be exact I typed ‘Is_home_try_on’ and ‘Is_purchase’ . I still have blank white screen instead of normal output in codecademy interface.

I guess I know the right answer after looking it up in Help section (the one that is above provided by codecademy as solution) but I really can not get my head aroud it and I want to know what I did wrong.

Is it possible so there is some kind of another problem in my code?

Thanks

The only other possibility I can see is that your code might not work in a real environment is if you’re referring to the tables/column names incorrectly (misspelling). But usually the program will give you an error for that.

It could just be that they wanted you to alias all the names of the columns. I don’t know.

As a test, try making these tables with dummy data in sqlite3 or db browser and then run the same sql query and see if it throws an error.

Hello,

You just had a typo in the column name (see comment below).

I’m running into the same problem with syntax errors and no feedback from the lesson. Sometimes I just work with a small number of lines at a time and add from there to eliminate having search a large number of lines for syntax errors.

1 Like