-3

I'm new in SQL query language. I have to write a SELECT statement to choose 3 attributes from two different tables. How do I write that?

Thanks in advance.

My base contains the following tables with the following data:

Product(maker, model, type) 
PC(code, model, speed, ram, hd, cd, price) 
Laptop(code, model, speed, ram, hd, screen, price) 
Printer(code, model, color, type, price) 

(From comment on David Browne's answer.)

And I should get the model, ram and screen from PC and Laptop tables, of the computers, whose price is higher then 1000.

  • Possible duplicate of [SQL Server, choosing from two TABLEs using IF statement inside WHERE statement depending on the parameter](https://stackoverflow.com/questions/2272906/sql-server-choosing-from-two-tables-using-if-statement-inside-where-statement-d) – dengApro Sep 16 '17 at 16:11

2 Answers2

0

In the normal case, join the tables using the foreign key column(s) on one table and the related primary key column(s) on the other table.

Post table DDL, sample data and desired results for a more specific answer.

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
  • My base contains the following tables with the following data: Product(maker, model, type) PC(code, model, speed, ram, hd, cd, price) Laptop(code, model, speed, ram, hd, screen, price) Printer(code, model, color, type, price) And I should get the model, ram and screen from PC and Laptop tables, of the computers, whose price is higher then 1000. – Windy Sep 16 '17 at 16:20
  • For that, true UNION ALL. – David Browne - Microsoft Sep 16 '17 at 17:05
0

You may use UNION ALL to combine the records from the tables as suggested by David.

SELECT model,
       ram,
       screen
  FROM pc
 WHERE price > 1000
 UNION ALL
SELECT model,
       ram,
       screen
  FROM laptop
 WHERE price > 1000
Ferdinand Gaspar
  • 2,043
  • 1
  • 8
  • 17