简体   繁体   English

比较两个具有不同字段的SQL表

[英]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. 我想知道是否可以使用带有两个字段名称不同的表的“ INNER JOIN”。

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). 我有一个名为47的表,其中有一个名为order_status的字段,该字段中的值为(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). 然后,我有另一个表,名为venermart_orderstatus,表中包含一个名为order_status_code的值(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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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