Victor York
Victor York

Reputation: 1681

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?

Upvotes: 1

Views: 68

Answers (2)

Goutam Pal
Goutam Pal

Reputation: 1763

Yeas it is possible

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

Upvotes: 0

Alex
Alex

Reputation: 8937

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

Upvotes: 2

Related Questions