I dont know key to find how to solve my problem. Please help me.
I have 2 table as
Table A:
ID Item
-------
SB SanBay
VP VanPhong
Table B:
Ma HangHoa
-------
1 AAA
2 BBB
3 CCC
4 DDD
And i want to select to :
Item HangHoa
------------
SanBay AAA
SanBay BBB
SanBay CCC
SanBay DDD
VanPhong AAA
VanPhong BBB
VanPhong CCC
VanPhong DDD
Thank a lots
CodePudding user response:
This is called a cross join. A cross join is a simple join but with no join conditions. Thus every record in A matches every record in B. Example:
Select item,hanghoa from A cross join B
or more simply and more commonly
select item,hanghoa from A,B
Both forms are equivalent, but the "cross join" syntax is probably a better habit because it says "yes I really did want to omit any join conditions"
CodePudding user response:
You could use the below CROSS JOIN
, A SQL CROSS JOIN
produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table if no WHERE
clause is used along with CROSS JOIN
.This kind of result is called as Cartesian Product.
select ta.Item, tb.HangHoa
from tableA ta cross join
tableB tb
Below is a link that will provide more infomation of required.