Home > database >  In mysql how to merge the two tables according to column
In mysql how to merge the two tables according to column

Time:09-15

As title, such as
Table 1

ID name gender
1 zhang SAN men
2 li si female
3 fifty men
4 liu six female

Table 2

ID district
1
in guangdong2 the sichuan
3 Beijing
Shanghai

The result of the merger is

Table 3
ID name gender district
Zhang SAN men guangdong
1Female sichuan
2, dick, and harry3 fifty men Beijing
4 liu six female Shanghai


In table 1 and table 2 do not have what relation, I just want to simple together

CodePudding user response:

SELECT * FROM table 1 and table 2.

CodePudding user response:

SELECT * FROM table 1 and table 2 WHERE table 1. ID=table 2. ID;

CodePudding user response:

Among the new table to store words:
The create table tb_3 as (select tb_1. ID, name, gender, district from tb_1, tb_2 where tb_1. ID=tb_2. ID);
From the middle table view:
Select * from tb_3;
Just a query:
Select * from tb_t, tb_2 where tb_1. ID=tb_2. ID;

CodePudding user response:

Select t1. Id, t1. The name, t2. The district from t1 join t2 on t1. Id=t2. Id;

CodePudding user response:

Atul gawande at the select Anderson d, a.n ame, ender, b. district from table 1 a
Left the join table 2 b on b.i d=Anderson, d

CodePudding user response:

Know what you mean,
First take a two table id
Select *, b. c. * from (
Select @ rownum:=@ + 1 rownum, rownum b. *
The from (
Select * from table 1 order by fields
- can be ordered by a field take rownum
(select @ rownum:=0) a
B) left the join (
Select @ rownum:=@ + 1 rownum, rownum b. *
The from (
Select * from table 1, (select @ rownum:=0) a
C)
On b.r ownum=c.r ownum
  • Related