简体   繁体   中英

select specific column only in mysql

my table-1 has 20 columns and table-2 has 15 columns. here i want to join two tables by user id . i use this bellow query

SELECT  * FROM   table_checkout_bidpack as t1 inner JOIN table_user_information 
as t2 ON t1.user_id=t2.user_id

This query selects 35 columns but i need to select on columns(user_name) in the second table

i know this work

select t1.col1,t1.col2,t1.col3,t1.col4,.....,t2.user_name 
FROM   table_checkout_bidpack as t1 inner JOIN table_user_information 
as t2 ON t1.user_id=t2.user_id

This looks very big any other ways to do this

select t1.*,t2.user_name 
FROM   table_checkout_bidpack as t1 inner JOIN table_user_information 
as t2 ON t1.user_id=t2.user_id
select t1.*,t2.user_name 
FROM   table_checkout_bidpack as t1 inner JOIN table_user_information 
as t2 ON t1.user_id=t2.user_id

* is a wildcard selector, by itself it will match all columns in all tables, but if you prefix it with table. it will only match columns in that table.

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