MySQL compare 2 table match columns

Posted on 2011-10-09
Last Modified: 2012-05-12
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?
Question by:pda4me

    Author Comment

    to clarify, I want to see out put like this

    Table1-columnName-->Table2-columnName-->Matching Data
    LVL 38

    Accepted Solution

    You could dynamically pull the column name like this:,282509,284806#msg-284806

    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".

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now