BLACK FRIDAY EXTRA SAVINGS EVENT - EXTENDED
START FREE

Subqueries as Values assesment

Screen link:
https://app.dataquest.io/m/2000601/scalar-subqueries-assessment/3/question-3

SELECT (SELECT first_name ||" "|| last_name
          FROM customer
         WHERE customer_id = 18) AS name,
       SUM(total) as total
  FROM invoice
 WHERE customer_id = 18;

What I expected to happen:

A table with

  • a column name containing the name of customer_id = 18
  • and a column total containing the SUM of purchase amount

Which is exactly what i got:

afbeelding

However, the feedback I get at the end is:

I’m unsure what is wrong and whether I misunderstood the question.
Does someone understand?

Your answer is basically correct. However, on Datatypes and Column Operations; Operations with Text we read. . .

SELECT 'Data' || 'quest' AS join_words

(…)

Notice how we enclosed the words Data and quest in single-quotes ('). This is how SQL identifies the words as strings; otherwise, it will interpret them as column names.

Use single quotes. Double quotes can cause trouble in other databases even though they basically work in SQLite.

1 Like

Hi Bruno,

OK. I thought double quotes and single quotes were interchangeable.
Are there cases when to use double quotes with SQL, or never?

I’m currently also enrolled in the Python career track.
Does the same apply to Python? Single instead of double quotes?

Thanks for your answer!

For sure there are. Some databases use double quotes for identifiers (e.g. column names, tables names…)

Say you have or want to have a column with a space in its name, say, first name. To refer to it you can use "first name".

No.