简体   繁体   中英

How to join column from table2 to table1 after a specified column of table1?

I have a query like this:

Select table1.*, table2.column1  from table1 join table2 on table1.column1=table2.column1

It works, but it puts the column in the end of the datagridview , but i have to put table2.column1 , after a specified column of table2 , and i have to use table1.* and i cant use listing of the table1 's columns is it possible?

And why exactly can't you use a list of all the fields?

NO , it's not possible to place a column in the middle of columns specified with * , not with pure SQL and not with dynamic.

Just specify them, don't be lazy, it's better practice:

SELECT table1.col1,
       table1.col2,
       table2.col1,
       table1.col3
 ..........

because i am using union queries, and the table names are changing and one table contains more colums than the other

if table1 differs, that above all should be a strong argument for specifing all needed fields separatly. In case of a new field in table1, your query would be broken, cause the number of fields will differ from the ones used in the next union.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM