• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

MySQL compare 2 table match columns

i have two tables Table1 and Table2 each with different column names but housing the same data.  Table 1 has a primary key called MLNUM and Table 2 has a primary key called MLSNUMBER for example but both contain a record with a matching value for their columns example: 201104995.

If I use a value that is found in both tables as the primary key (example: 201104995)  how can I compare the two tables and get the names of columns where the data matches for that record in each table..

For example, if I use 201104995, I can manually match up that column City in Table1 and column ListingCity in Table2 as both have the same data.

There is close to 100 columns in each table so this is very hard to do manually.  How can save some work and do this with a query?
1 Solution
pda4meAuthor Commented:
to clarify, I want to see out put like this

Table1-columnName-->Table2-columnName-->Matching Data
Aaron TomoskyTechnology ConsultantCommented:
You could dynamically pull the column name like this:

I know you can also "Order by 1" where 1 is the first column but I don't think you can "select 1 from tablename".

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now