select
display_name
, 'Table one' as TableName
from
one
where
[display_name] = 'Искомое слово'
union all
select
display_name
, 'Table two' as TableName
from
two
where
[display_name] = 'Искомое слово'
union all
select
display_name
, 'Table three' as TableName
from
three
where
[display_name] = 'Искомое слово'
SELECT DISTINCT
planet.*
FROM
planet
INNER JOIN
planet_resource
ON
planet_resource.planet_id = planet.id
INNER JOIN
planet_resource_person
ON
planet_resource_person.resource_id = planet_resource.id
INNER JOIN
people_planet
ON
people_planet.people_id = planet_resource_person.person_id
AND people_planet.planet_id = planet.id
WHERE
people_planet.people_id = ID нужного человека
SELECT DISTINCT
orders.user_id
FROM
orders
INNER JOIN
orders AS canceledOrders
ON
canceledOrders.user_id = orders.user_id
AND canceledOrders.status = orders.status
AND canceledOrder.order_id <> orders.order_id
AND canceled.timestamp - orders.timestamp BETWEEN 0 AND 1800
WHERE
orders.status = 'cancel'
SELECT pot_volt.room_id rid, pot_volt.pot_id pid,
setp_volt voltTarget, raw_volt volt, -- pot_volt
avg_amp amp, -- pot_power
cr, caf2, -- bath_an
metal_height meHeight, bath_height baHeight, temperature baTemp -- pot_bath
FROM pot_volt
JOIN pot_power ON pot_power.pot_id=pid AND pot_power.room_id=rid AND cast(pot_volt.date_stamp as date) = cast(pot_power.date_stamp as date)
JOIN bath_an ON bath_an.pot_id=pid AND bath_an.room_id=rid AND cast(bath_an.date_stamp as date) = cast(pot_volt.date_stamp as date)
JOIN pot_bath ON pot_bath.pot_id=pid AND pot_bath.room_id=rid AND cast(pot_bath.date_stamp as date) = cast(pot_volt.date_stamp as date)
WHERE rid=1 AND pid=36 AND pot_volt.date_stamp BETWEEN 1497336487 AND 1498027687
ORDER BY pot_volt.date_stamp DESC
SELECT
t1.*
, count(t2.id) AS count
FROM
table AS t1
INNER JOIN
table AS t2 on t1.id = t2.parent
INNER JOIN
table AS t3 on t2.id = t3.parent
INNER JOIN
table AS t4 on t3.id = t4.parent
INNER JOIN
table AS t5 on t4.id = t5.parent
INNER JOIN
table AS t6 on t5.id = t6.parent
WHERE
t1.parent IS NULL
GROUP BY
t1.id
HAVING
count(t2.id) >= 3
SELECT
COUNT(DISTINCT [orderT].[user]) as [Orders]
, [Hours].[Hour]
FROM
(
VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23)
) AS [Hours]([Hour])
LEFT OUTER JOIN
[orderT]
ON
datepart(hh, [orderT].[date]) = [Hours].[Hour]
WHERE
[orderT].[Operation] LIKE 'newOrder'
AND [orderT].[date] >= Convert(datetime, '2014-11-06 00:00:00')
AND [orderT].date < Convert(datetime, '2014-11-06 23:59:59')
GROUP BY
[Hours].[Hour]