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';
Anda bisa tidak bisa buat "table2" diturunkan di baris karena pembatasan penggunaan LIMIT di subkueri. Kalau tidak, itu akan menjadi
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;
Sunting:Batasan LIMIT dalam subkueri sebagian besar berlaku untuk IN, bukan tabel turunan
Sunting 2:menambahkan lebih banyak alias