E
E
Egorithm2016-05-19 15:26:33
MySQL
Egorithm, 2016-05-19 15:26:33

MySQL. How to combine fields with the same data from different tables in a query?

There is a database computer_company , it has 4 tables (which can be seen in the picture).
76b70c24e9084c228b8f3eb322fd60fa.pngThe task is:
"Find the model numbers and prices of all products (of any type) released by the ASUS manufacturer."
Here's what I got:

SELECT product.model, pc.price, laptop.price, printer.price
FROM product
INNER JOIN pc ON product.model = pc.model
INNER JOIN laptop ON product.model = laptop.model
INNER JOIN printer ON product.model = printer.model
WHERE product.maker LIKE "ASUS";

Outputs Empty set , which is not surprising.
I need to merge the price fields from all three tables into one. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2016-05-19
@EgoRusMarch

Basically, you've already done everything. Empty set apparently means that the request returned an empty set. If it bothers you that the fields are named the same, then there is the as keyword:
The query returns an empty set, most likely due to INNER JOIN, because when using it, it is required that all three tables simultaneously have data corresponding to each row from the table specified in from, which, apparently, is not the case in your case.
Use OUTTER JOIN aka LEFT JOIN.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question