1

I am typing in this query:

i13 display name, price and sum quantity for all fruit, even ones with quantity null

select inventory.fruitID
concat( "$", quantity * price ) as "value"
from fruit right join inventory
on fruit.fruitID = inventory.fruitID;

I am getting this message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( "$", quantity * price ) as "value" from fruit right join inventory on fruit.fr' at line 3

What am I doing wrong?

4
  • are the quotes around the query single '' ie not double "" Commented Apr 22, 2018 at 22:24
  • yes they're the double marks " Commented Apr 22, 2018 at 22:25
  • try single .... Commented Apr 22, 2018 at 22:25
  • 2
    There's a comma missing before the concat(). Commented Apr 22, 2018 at 22:27

1 Answer 1

1

First, if you want all fruit, then use a left join with fruit as the first table. I think the query you are trying for is:

select f.fruitID, f.price, sum(i.quantity) as total_quantity
from fruit f left join
     inventory i
     on f.fruitID = i.fruitID
group by f.fruitID, f.price;

Notes:

  • Table aliases make the query easier to write and to read.
  • This assumes that price is in the fruit table.
  • If you want all fruit, then fruit should be the first table in the left join.
  • You see to want to sum the inventory, so that requires an aggregation function and group by.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.