Home > database >  How to put the two tables in the id number of the same content is displayed in a table?
How to put the two tables in the id number of the same content is displayed in a table?

Time:09-17

A table
Township village (community) family member id card number, personal attributes household name householder account amount
Neither son bay township sheep HSS shimosho club night zhao Ming chuan village 622421199 XXXXXXX inputting tent card door zhi-bing Yang 221610 xxxx00552072 70
Rural village of sheep HSS sichuan white even son bay bay club Liu Liancai XXXXXXX document 622427194 tent card door zhao-ping liu 221610 xxxx0545405 70
Neither son bay township sheep HSS Yang Ruisen chuan village shimosho club 6224271949 XXXXXX by inputting tent card door xin-cheng Yang 623065 xxxx10022003 70
Neither son bay township sheep HSS sichuan village shimosho sino-japanese war of 62242719500 XXXXX inputting tent card door xin-cheng Yang 623065 xxxx00333727 70
Table B
Township and village villagers name id number type account amount
Shop in the town of Chiang's abundant cooking club night Ming zhao village 622421199 XXXXXXX three kinds of low 221210 xxxxx028457o 120
Shop in the town of Chiang's abundant cooking club Li Xiangying village 6224271947 XXXXXX three kinds of low 221210 xxxxxx010284 70
Shop in the town of Chiang's Yang village club Yang Fawen 62242719910 XXXXXX on four types of low 2212101 xxxxx000070 70
Shop in the town of jiang village on club xiu-yan zhang Yang 622427196504 XXXXX four types of low 22121 xxxxx02822381 70
Shop in the town of Chiang's Yang village club Yang Zengren 6224271953 XXXXXX on four types of low 22121 xxxxxxx822381 70

Want

Township village (community) family member id card number, personal attributes rural villagers name id number
Neither son bay township sheep HSS shimosho club night zhao Ming chuan village 622421199 XXXXXXX inputting tent card shop town in Chiang's abundant cooking club night Ming zhao village 622421199 XXXXXXX


Id number is the only value!

CodePudding user response:

SELECT * FROM A table A
The JOIN table B B
ON a. id number=b. id number

CodePudding user response:

 USE tempdb for 
GO
IF OBJECT_ID (' dbo. [A]) IS NOT NULL
DROP TABLE dbo. [A]
GO
The CREATE TABLE dbo. [A] (
[town] NVARCHAR (MAX)
, [village (community)] NVARCHAR (MAX)
, [family] NVARCHAR (MAX)
, id card number NVARCHAR (MAX)
, personal attributes NVARCHAR (MAX)
, head of the household name NVARCHAR (MAX)
, head of the household accounts NVARCHAR (MAX)
, [amount] NVARCHAR (MAX)
)
GO
SET NOCOUNT ON
INSERT INTO dbo. [A] VALUES (N 'neither son bay township, N' sheep HSS chuan village shimosho club ', N 'night zhao Ming', N '622421199 XXXXXXX, N' cross tent card door ', N 'zhi-bing Yang', N '221610 xxxx00552072', N '70')
INSERT INTO dbo. [A] VALUES (N 'neither son bay township, N' sheep HSS sichuan White House bay village club ', N 'Liu Liancai', N '622427194 XXXXXXX, N' cross tent card door ', N 'zhao-ping liu', N '221610 xxxx0545405', N '70')
INSERT INTO dbo. [A] VALUES (N 'neither son bay township, N' sheep HSS chuan village shimosho club ', N 'Yang Ruisen', '6224271949 XXXXXX' N, N 'cross tent card door', N 'xin-cheng Yang', N '623065 xxxx10022003', N '70')
INSERT INTO dbo. [A] VALUES (N 'neither son bay township, N' sheep HSS chuan village shimosho club ', N 'sino-japanese war', '62242719500 XXXXX' N, N 'cross tent card door', N 'xin-cheng Yang', N '623065 xxxx00333727', N '70')
GO
IF OBJECT_ID (' dbo. [B]) IS NOT NULL
DROP TABLE dbo. [B]
GO
The CREATE TABLE dbo. [B] (
[town] NVARCHAR (MAX)
, [19] NVARCHAR (MAX)
, [name] NVARCHAR (MAX)
, id card number NVARCHAR (MAX)
, [type] NVARCHAR (MAX)
, [account] NVARCHAR (MAX)
, [amount] NVARCHAR (MAX)
)
GO
SET NOCOUNT ON
INSERT INTO dbo. [B] VALUES (N 'shop in town,' N 'Chiang's mountain abundant cooking club', N 'night zhao Ming', N '622421199 XXXXXXX, N' three kinds of low ', N '221210 xxxxx028457o', N '120')
INSERT INTO dbo. [B] VALUES (N 'shop in town,' N 'Chiang's mountain abundant cooking club', N 'Li Xiangying', '6224271947 XXXXXX' N, N 'three kinds of low', N '221210 xxxxxx010284', N '70')
INSERT INTO dbo. [B] VALUES (N 'shop in town,' N 'on Chiang's Yang village club', N 'Yang Fawen', '62242719910 XXXXXX' N, N 'four types of low', N '2212101 xxxxx000070', N '70')
INSERT INTO dbo. [B] VALUES (N 'shop in town,' N 'on Chiang's Yang village club', N 'xiu-yan zhang', '622427196504 XXXXX' N, N 'four types of low', N '22121 xxxxx02822381', N '70')
INSERT INTO dbo. [B] VALUES (N 'shop in town,' N 'on Chiang's Yang village club', N 'Yang Zengren', '6224271953 XXXXXX' N, N 'four types of low', N '22121 xxxxxxx822381', N '70')
-- -- -- -- -- -- -- -- -- -- -- -- -- -- above for testing table and test data -- -- -- -- -- -- -- -- -- -- -- -- -- --

SELECT
A. the villages and towns
, a. [village (community)]
A. family members,

a. id number,, a. personal attribute
, b. township
, b. villagers
B. name

a. id number,FROM A INNER JOIN B ON a. [id]=b. [id]


  • Related