Mohammed Bathily
Mohammed Bathily

Reputation: 25

Join two tables with two identical columns

I have two tables: Log and Location, there is no relationship between the two. However in each table there are columns X and Y. I would like to make a query selecting the rows having the corresponding X and Y columns of the two tables with the requirement that the condition is just checked at the log table.

Log table: Id, X, Y

Table Location: X, Y, Address

WHAT I NEED:

|    ID      X         Y       Address   |
|    1      123        854       50      |
|    2      478        697       60      |

Upvotes: 0

Views: 1257

Answers (2)

Michael
Michael

Reputation: 2414

It sounds like you want to join the two tables based on common X and Y values. This would do that:

SELECT Log.ID, Log.X, Log.Y, Location.Address 
FROM Log, Location
WHERE Log.X = Location.X
    AND Log.y = Location.Y

Upvotes: 0

Maksym Fedorov
Maksym Fedorov

Reputation: 6456

You can use JOIN statement. For example:

SELECT 
   log.id,
   log.x,
   log.y
   location.address
FROM log
LEFT JOIN location ON log.x=location.x AND log.y=location.y

Upvotes: 2

Related Questions