-- 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
CREATE VIEW V AS (
SELECT i.country,i.year,p.pop,f.food,i.income FROM
INCOME i
LEFT JOIN
POP p
ON
i.country=p.country
LEFT JOIN
Food f
ON
i.country=f.country
WHERE
i.year=p.year
AND
i.year=f.year
);
SELECT
users_first_name,
users_last_name
FROM
(
(
SELECT
users.first_name AS users_first_name,
users.last_name AS users_last_name
FROM
users
INNER JOIN companies ON companies.id = users.company_id
WHERE
(
users.last_name LIKE 'TERM%'
)
)
UNION
DISTINCT (
SELECT
users.first_name AS users_first_name,
users.last_name AS users_last_name
FROM
users
INNER JOIN companies ON companies.id = users.company_id
WHERE
(users.first_name LIKE 'TERM%')
)
UNION
DISTINCT (
SELECT
users.first_name AS users_first_name,
users.last_name AS users_last_name
FROM
users
INNER JOIN companies ON companies.id = users.company_id
WHERE
(companies.name LIKE 'TERM%')
)
) AS union1;
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