简体   繁体   中英

Comparing two SQL tables with different different fields

I would like to know if it it possible to use for example an "INNER JOIN" with two table which have different field names.

Here is an example of my problem:

I have a table called virtuemart_orders where there is a field called order_status and which in this field the values are (P, R, X, C).

Then I have another table which is called virtuemart_orderstatus with a field named order_status_code with the values (P, R, X, C).

The thing is that I would like to be able to join these two tables using these fields because they are the only ones which seem more or less alike.

Would this be possible without having to change the name of the fields or anything else?

You don't need to change the names of your columns. Just specify them in your query

 SELECT * FROM virtuemart_orders T1
 INNER JOIN virtuemart_orderstatus T2
 ON T1.order_status=T2.order_status_code

是的,有可能

select t1.*,t2.* from t1 inner join t2 on (t1.order_status = t2.order_status_code)

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