我有2张桌子
User Code SubMenuID
usercol menucol
----------- -------------
AB Sub-01
Alam Sub-02
CSRL
Run Code Online (Sandbox Code Playgroud)
我想像这样展示他们
usercol menucol
---------- ------------
AB Sub-01
AB Sub-02
Alam Sub-01
Alam Sub-02
CSRL Sub-01
CSRL Sub-02
Run Code Online (Sandbox Code Playgroud)
我怎么能用sql查询得到这个?这会非常有帮助:)
And*_*ter 10
Since the tables are not related by a foreign key relationship, you can not join them - what you want as a result, is the Cartesian product from the two tables. This is achieved by selecting from both tables without any additional join condition (this is also called a cross join):
mysql> SELECT * FROM userCode, SubMenuId;
Run Code Online (Sandbox Code Playgroud)
This query combines all rows from the first table with all rows from the second table.
+---------+---------+
| usercol | menucol |
+---------+---------+
| AB | Sub-01 |
| AB | Sub-02 |
| Alam | Sub-01 |
| Alam | Sub-02 |
| CSRL | Sub-01 |
| CSRL | Sub-02 |
+---------+---------+
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13332 次 |
| 最近记录: |