0% found this document useful (0 votes)
4 views

Інфа8

The document outlines the creation of two SQL tables: 'imitation_jewelry' and 'composition', along with their respective fields and relationships. It includes sample data insertion for both tables and demonstrates various SQL SELECT queries to retrieve data through different types of joins. The queries aim to display the number and name of imitation jewelry items along with their corresponding composition values.

Uploaded by

9wprzfxyrh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Інфа8

The document outlines the creation of two SQL tables: 'imitation_jewelry' and 'composition', along with their respective fields and relationships. It includes sample data insertion for both tables and demonstrates various SQL SELECT queries to retrieve data through different types of joins. The queries aim to display the number and name of imitation jewelry items along with their corresponding composition values.

Uploaded by

9wprzfxyrh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

CREATE TABLE imitation_jewelry (

id INT PRIMARY KEY,


name VARCHAR(50),
price INT,
number INT,
net_profit_GRN INT
);

CREATE TABLE composition (


id INT PRIMARY KEY,
number_id INT,
value INT,
FOREIGN KEY (number_id) REFERENCES imitation_jewelry(id)
);

INSERT INTO imitation_jewelry (id, name, price, number, net_profit_GRN) VALUES (1, 'каблучка', 15,
10,40);
INSERT INTO imitation_jewelry (id, name, price, number, net_profit_GRN) VALUES (2, 'браслет', 40,
20,20);
INSERT INTO imitation_jewelry (id, name, price, number, net_profit_GRN) VALUES (3, 'чокер', 50,
25,25 );
INSERT INTO imitation_jewelry (id, name, price, number, net_profit_GRN) VALUES (4,
"підвіска",25 ,15 , 12);

INSERT INTO composition(id, value, number_id) VALUES (1, 20, 1);


INSERT INTO composition(id, value, number_id) VALUES (2, 25, 1);
INSERT INTO composition(id, value, number_id) VALUES (3, 25, 1);
INSERT INTO composition(id, value, number_id) VALUES (4, 15, 2);
INSERT INTO composition(id, value, number_id) VALUES (5, 40, NULL);

SELECT * FROM imitation_jewelry JOIN composition on imitation_jewelry.id =


composition.number_id;

SELECT imitation_jewelry.number, imitation_jewelry.name, composition.value FROM


imitation_jewelry JOIN composition on imitation_jewelry.id = composition.number_id;

SELECT imitation_jewelry.number, imitation_jewelry.name, composition.value FROM


imitation_jewelry LEFT JOIN composition on imitation_jewelry.id = composition.number_id;

SELECT imitation_jewelry.number, imitation_jewelry.name, composition.value FROM


imitation_jewelry RIGHT JOIN composition on imitation_jewelry.id = composition.number_id;

You might also like