You are on page 1of 15

Purpose Returns the records that have matching values in both tables

Exemplu
Sacul 1: porumb si mazare
Sacul 2: fasole si mazare

Vrei sa alegi doar mazarea din cei doi saculeti ca sa faci o mancarica de mazare
Table A

ASIN Title Brand


B01 Shampoo Garnier
B03 Chocolate Milka
B04 Notebook Pigna
B08 Pen Pensan

SELECT *
FROM Table A INNER JOIN Table B
ON A.ASIN = B.ASIN

Result

ASIN Title Brand Keywords A+ Content


B01 Shampoo Garnier shampoo;hair Yes
B03 Chocolate Milka chocolate;sweet;desert No
Table B

ASIN Keywords A+ content


B01 shampoo;hair Yes
B03 chocolate;sweet;desert No
B07 laptop;device Yes
B09 kitchen;utensil;silicone No
Purpose returns all records from the left table and the matched record from the right

Exemplu
Sacul 1: porumb si mazare
Sacul 2: fasole si mazare

Vrei sa pui mazarea si porumbul intr-un saculet pentru a hrani gainile. Asa ca pastrezi ce e in saculetul 1 si cauti doar mazarea
cord from the right table
Table A

ASIN Title Brand


B01 Shampoo Garnier
B03 Chocolate Milka
B04 Notebook Pigna
B08 Pen Pensan

SELECT *
FROM Table A LEFT JOIN Table B
ON A.ASIN = B.ASIN

Result

ASIN Title Brand Keywords A+ Content


B01 Shampoo Garnier shampoo;hair Yes
B03 Chocolate Milka chocolate;sweet;desert No
B04 Notebook Pigna NULL NULL
B08 Pen Pensan NULL NULL

etul 1 si cauti doar mazarea din saculetul 2


Table B

ASIN Keywords A+ content


B01 shampoo;hair Yes
B03 chocolate;sweet;desert No
B07 laptop;device Yes
B09 kitchen;utensil;silicone No
Purpose returns all records from the right table and the matched record from the left

Exemplu
Sacul 1: porumb si mazare
Sacul 2: fasole si mazare

Vrei sa pui mazarea si fasolea intr-un saculet pentru a hrani gainile. Asa ca pastrezi ce e in saculetul 2 si cauti doar mazarea din
record from the left table
Table A

ASIN Title Brand


B01 Shampoo Garnier
B03 Chocolate Milka
B04 Notebook Pigna
B08 Pen Pensan

SELECT *
FROM Table A RIGHT JOIN Table B
ON A.ASIN = B.ASIN

Result

ASIN Title Brand Keywords A+ Content


B01 Shampoo Garnier shampoo;hair Yes
B03 Chocolate Milka chocolate;sweet;desert No
B07 NULL NULL laptop;device Yes
B09 NULL NULL kitchen;utensil;silicone No

l 2 si cauti doar mazarea din saculetul 1


Table B

ASIN Keywords A+ content


B01 shampoo;hair Yes
B03 chocolate;sweet;desert No
B07 laptop;device Yes
B09 kitchen;utensil;silicone No
Purpose returns all records when there is a match in either left or right table

Exemplu
Sacul 1: porumb si mazare
Sacul 2: fasole si mazare

Vrei sa te lauzi cu cat de mare este productia din gradina si rastorni continutul celor 2 saculeti intr-un sac mare ca sa il arati ve
right table
Table A

ASIN Title Brand


B01 Shampoo Garnier
B03 Chocolate Milka
B04 Notebook Pigna
B08 Pen Pensan

SELECT *
FROM Table A FULL OUTER JOIN Table B
ON A.ASIN = B.ASIN

Result

ASIN Title Brand Keywords


B01 Shampoo Garnier shampoo;hair
B03 Chocolate Milka chocolate;sweet;desert
B04 Notebook Pigna NULL
B07 NULL NULL laptop;device
B08 Pen Pensan NULL
B09 NULL NULL kitchen;utensil;silicone

un sac mare ca sa il arati vecinului


Table B

ASIN Keywords A+ content


B01 shampoo;hair Yes
B03 chocolate;sweet;desert No
B07 laptop;device Yes
B09 kitchen;utensil;silicone No

A+ Content
Yes
No
NULL
Yes
NULL
No
Table A Table B Table C

ASIN ASIN no ASIN


Address Address
INNER JOIN
INNER JOIN

SELECT *
FROM TABLE A INNER JOIN TABLE B ON A.ASIN = B.ASIN INNER JOIN TABLE C ON B.ADDRESS = C.ADDR
WHERE

Table A Table B Table C

ASIN ASIN ASIN

SELECT *
FROM TABLE A INNER JOIN TABLE B ON A.ASIN = B.ASIN INNER JOIN TABLE C ON A.ASIN = C.ASIN
SELECT
A.X
B.Y

TRUTH
4TB 300GB 2TB
ON B.ADDRESS = C.ADDRESS

TABLE A TABLE B TABLE C


ASIN ASIN ASIN
BRAND KEYWORDS FT STATUS
TITLE

SELECT *
FROM TABLE A INNER JOIN TABLE B ON A.ASIN = B.ASIN INNER JOIN TABLE C ON A

ON A.ASIN = C.ASIN ASIN


BRAND
TITLE
KEYWORDS
FT STATUS
IN INNER JOIN TABLE C ON A.ASIN = C.ASIN

You might also like