mysql merge two tables with different columns code example

Example 1: mysql join two tables

SELECT user_id, user_name
FROM users
UNION
SELECT organization_id, organization_name
FROM organizations

Example 2: how to combine 2 tables in MySQL

create table yourTableName
(
   select *from yourTableName1
)
UNION
(
   select *from yourTableName2
);

Example 3: how to select multiple columns from different tables in mysql

-- MySQL 
-- t1 = table1
-- dt2 = column of table
SELECT t1.dt2, t2.dt4, t2.dt5, t2.dt3 #get dt3 data from table2
FROM table1 t1, table2 t2 -- Doesn't need to have t1, or t2
WHERE t1.dt2 = 'asd' AND t2.dt4 = 'qax' AND t2.dt5 = 456

Tags:

Sql Example