I have two tables table1 and table2, i need to write a select query which will list me the columns that exist in both the tables. (mysql)
I need to do for different tables (2 at a time)
Is this possible?
I tried using INFORMATION_SCHEMA.COLUMNS
but am not able to get it right.
(INNER) JOIN : Returns records that have matching values in both tables. LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table. RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the left table.
Open the workbooks you want to compare. Go to the View tab, Window group, and click the View Side by Side button. That's it!
Navigate to the "Home" option and select duplicate values in the toolbar. Next, navigate to Conditional Formatting in Excel Option. A new window will appear on the screen with options to select "Duplicate" and "Unique" values. You can compare the two columns with matching values or unique values.
Compare two tables by using joins. To compare two tables by using joins, you create a select query that includes both tables. If there is not already an existing relationship between the tables on the fields that contain the corresponding data, you create a join on the fields that you want to examine for matches.
SELECT a.COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS a
JOIN INFORMATION_SCHEMA.COLUMNS b
ON a.COLUMN_NAME = b.COLUMN_NAME
AND b.TABLE_NAME = 'table2'
AND b.TABLE_SCHEMA = database() //or manually enter it
WHERE a.TABLE_NAME = 'table1'
AND a.TABLE_SCHEMA = database(); //or manually enter it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With