Using SQL statements to merge two unrelated tables?

Updated on technology 2024-03-21
9 answers
  1. Anonymous users2024-02-07

    You can simply use the SQL statement query result merging method. select * from a union all select * from b union all select * from c

  2. Anonymous users2024-02-06

    Select * from aunion allselect * from bunion allselect * from c c table is your new blank table, which is similar to the previous question.

  3. Anonymous users2024-02-05

    1. The first is to use a temporary table to put all the data in one table.

    insert into qunlist select * from qunlist89,90,91,92;

    Then query in the qunlist.

    2. The second way is to use the union all way to query.

    select * from qunlist89union all

    select * from qunlist90;

  4. Anonymous users2024-02-04

    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.

  5. Anonymous users2024-02-03

    Preferably, you should merge the data in Table 1, Table 2, and Table 3 into a table and use Union All to merge them together. Ignore whether the names are duplicated or not.

    However, when performing the merger, it is necessary to put a label on each data to be merged, representing the data from which table this is, and this label is finally used to distinguish the different scores of the same person.

    The merged data is converted from row to column.

  6. Anonymous users2024-02-02

    select a.Entrant's name, bLong-distance running score, cSwimming score, dHigh Jump Score from (

    select Participant Name from (.

    Select Participant's Name from Table 1

    UnionSelect Participant Name from Table 2 UnionSelect Participant Name from Table 3) as t) as a

    Left join Table 1 as b

    on a.Entrant's name, bEntrant's name.

    Left join Table 2 as c

    on a.Participant's name = cEntrant's name.

    Left join Table 3 as d

    on a.Participant's name = dEntrant's name.

  7. Anonymous users2024-02-01

    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.

  8. Anonymous users2024-01-31

    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.

  9. Anonymous users2024-01-30

    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

Related questions
8 answers2024-03-21

sql2008 statement:

select name = case when num = 1 then a else''end, grades, subjects. >>>More

5 answers2024-03-21

F get domain contrast is a formatting function (should be written by yourself), the first parameter (arg prod spec id) according to the second parameter (120) formatting and return the result to the v bill code, according to the function naming method, the above ** should be the standard format for getting the date.

5 answers2024-03-21

With a view or an index.

create index >>>More

4 answers2024-03-21

Oracle does not have SQL statement backup, only exp export or RMAN backup, are not SQL, RMAN is a standard block backup, the premise is that the database must be archived, and then RMAN backup can be carried out, this method can be used for databases with a large amount of data, the speed will be relatively fast, the specific method can be checked from the Internet, it is not very difficult, but it is more cumbersome, there is an exp export, this is to directly export the table in the database to the city dmp file, The specific syntax is: >>>More

5 answers2024-03-21

The foreground interacts with the data stored internally. >>>More