-
The first way is to do a correlation query, which already has the answer.
The second method is to create a view, which is also given above.
The third way is to create a new table, which gives the answer, but I have an easier way:
For example, if the fields in the Geren table are: id, a, b, and cgeren2, the fields in the table are: id, d, e, f, and the script to create a new table is as follows
create table geren_all asselect , from geren g1, geren2 g2where = ;
-
Create a new table to store the merged data.
Insert data. insert into a new table ( column name. select column name. from source table 1 and source table 2 where source table = source table
-
* from geren inner join geren2 on
This query makes it possible to find the data in both tables. If you have other requirements, you can try it with a join.
2.If it's the interface to be displayed. Then 1 is enough. If you want to deposit it in a table. You create a table based on the queried table structure. Insert into (select ...)That's it.
-
What do you mean? If it's just that the IDs are different, it doesn't make sense for you to define two tables, but you can combine one table to express one meaning.
You can import the records from another table onto one.
It's also possible to create a view.
-
Wouldn't it be nice to use a foreign key to link?
foreign
-
1. First, open the SQL Server management tool and use the SELECT statement to query the records of the current table.
2. Next, you need to sort the table by row number, and save the sorted table to the temporary table.
3. Next, write the update statement, here we use table association, as shown in the following figure, the sorting field of the temporary table is reassigned to the sorting field of the table through association.
4. Then remember to delete the temporary table at the end, as shown in the figure below, if you don't delete the temporary table, an error will be reported next time.
5. After executing the SQL statement, you will find that the value of the px field in the record has not changed, as shown in the following figure, which is due to the problem of sorting method.
6. Next, sort in the row number by the descending order of the px field, as shown in the following figure, after the execution, you will find that the value of the px field has changed, that is, the sql merge shows that the two tables without association are successful.
-
If it's a vertical merge, use Union All
There are two tables A and B that are added
The table structure has two fields: date1 and a2
Table b has a field date1
select date1,a2 from (select date1,a2 from a
union all
select date1,null from b)order by date1;
Note that the number of fields in the two tables in union all must be the same, and the missing fields must be filled with null.
Sorting must be done outside of the subquery.
-
where [fields in table a] = [fields in table b].If you can't meet this condition, it is recommended that you reconstruct the logical structure of the data.
In the case of where, you can set the sorting with the sorting condition. order by + ascending or descending.
-
Use union or union all
For example, select * from a union, all select * from b, and then nest a layer of queries to sort the time order by
Click on this.
Server Name: Just enter a dot. >>>More
I'll give you a copy :
PB connects to multiple databases. >>>More
Tools Material: Management Studio.
1. First, on the desktop, click on the "Management Studio" icon. >>>More
select min(score) from tablename where time>mintime and timemintime and time=starttime> and time<=endtime group by stuid; >>>More
If the parents do not have the financial strength to raise their son, when their daughter is an adult, and she has worked and has an income, she actually needs to help her parents raise her younger brother, but during the period of raising her younger brother, as a daughter, she should only help her parents relieve the financial pressure, not all of them need her daughter to come out. After giving birth to their second child, the husband and wife who relied on the subsistence allowance reported wanted to let their eldest daughter raise them because their physical and economic conditions were not very good, and they were also unable to let their sons be well controlled. >>>More