CREATE TEMPORARY TABLE table2
AS
SELECT distinct src_ip, vlan_id from video_2
WHERE date_pl >= '2011-11-29 00:00' AND date_pl <= '2011-12-05 23:55'
ORDER BY rand()
LIMIT 50;
SELECT src_ip, vlan_id, video_id, area
FROM
video_2
JOIN
table2 ON video_2.src_ip = table2.src_ip AND video_2.vlan_id = table2.vlan_id';
Du kan kan ikke lav "table2" afledt i linje på grund af restriktioner for brugen af LIMIT i underforespørgsler. Ellers ville det være
SELECT
v2.src_ip, v2.vlan_id, v2.video_id, v2.area
FROM
video_2 v2
JOIN
(SELECT distinct v.src_ip, v.vlan_id from video_2 v
WHERE v.date_pl >= '2011-11-29 00:00' AND v.date_pl <= '2011-12-05 23:55'
ORDER BY rand()
LIMIT 50
) table2 ON v2.src_ip = table2.src_ip AND v2.vlan_id = table2.vlan_id;
Rediger:Begrænsninger LIMITS i underforespørgsler gælder for det meste IN, ikke afledte tabeller
Rediger 2:tilføjede flere aliaser