Select accessing two tables

1

I have a Product table, with the marker, model, and type fields.

A second table for laptops has its fields related to price, RAM, other fields, and the model, which is the same as the Product table.

How to make a select that tells me the marker of a product accessing its model code?

    
asked by anonymous 01.09.2016 / 21:15

1 answer

1

How about this?

SELECT p.marker
FROM produto p
INNER JOIN laptops lap ON p.model = lap.model
WHERE lap.model = ?

Where ? is the laptop model.

However, you may want to show multiple product and laptop fields:

SELECT p.marker, p.type, p.model, lap.preco, lap.ram, lap.outrocampo
FROM produto p
INNER JOIN laptops lap ON p.model = lap.model
WHERE lap.model = ?

However, if on the other hand you want only model and nothing else, then considering that the query does not contain any fields of the laptops table and that the code given to the laptop is the same as the produto , you could soon simplify to have this:

SELECT p.marker
FROM produto p
WHERE p.model = ?
    
01.09.2016 / 21:44