| |

VerySource

 Forgot password?
 Register
Search
View: 257|Reply: 3

On the question of adding two tables

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-2 01:00:01
| Show all posts |Read mode
Is there any way to combine two tables (possibly with different fields) into one table:
Table A
Field 1 field 2 field 3
1 aa1 bb1
2 aa2 bb2
4 aa4 bb4

Table B
Field 1 field 2 field 4
3 aa3 cc3
5 aa5 cc5
6 aa6 cc6

Synthesized table:
Field 1 Field 2 Field 3 Field 4
1 aa1 bb1
2 aa2 bb2
3 aa3 cc3
4 aa4 bb4
5 aa5 cc5
6 aa6 cc6

The value of field 1 in both tables cannot be duplicated
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 Unknown

Post time: 2020-3-18 21:45:01
| Show all posts
The value of field 1 in both tables cannot be duplicated

This means that the data of field 1 of table a cannot be the same as the data of field 1 of table b?

If so:

select field 1, field 2, field 3, '' as field 4 from table A
UNION
select field 1, field 2, '' as field 3, field 4 from table B

If that sentence means that the content of field 1 in table a or table b is not duplicated

select isnull (a.field1, b.field1), isnull (a.field2, b.field2), a.field3, b.field4
from table A a full join table B b
on a. field 1 = b. field 1
Reply

Use magic Report

1

Threads

19

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-19 19:00:01
| Show all posts
sele aaa, bbb, ccc, space (10) as ddd from table a;
union;
sele aaa, bbb, space (10) as ccc, ddd from table b
Reply

Use magic Report

0

Threads

1

Posts

0.00

Credits

Newbie

Rank: 1

Credits
0.00

 China

Post time: 2020-3-30 13:26:57
| Show all posts
Can use functions
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list