我有兩個表的屬性和property_imagesMySQL的加入,從一個表和第一行中的所有行從另一個表
where properties.pid = property_images.pid
屬性可以有一個以上的圖像,我有選擇的所有屬性和第一屬性圖像
我有兩個表的屬性和property_imagesMySQL的加入,從一個表和第一行中的所有行從另一個表
where properties.pid = property_images.pid
屬性可以有一個以上的圖像,我有選擇的所有屬性和第一屬性圖像
select
t1.* ,
t2.image
from properties as t1
left join (
select
min(id),
pid,
image
from property_images
group by pid) as t2
on t2.pid = t1.pid
select * from property a
left join (select * from property_Images b group by pid) s on s.pid=a.pid ;
select
pro.*
from properties as pro
left join (
select
min(id),
pid,
image
from property_images
group by pid) as pro_img
on pro.pid = pro_img.pid
select *
from properties as t1
left join property_images t2 on (t1.pid=t2.pid)
where t2.id in
(select min(id) from property_images where property_images.pid=t2.pid)
OR假設有在property_images一個唯一的密鑰ID:
select *
from properties as t1
left join (select min(id) minID, pid from property_images group by pid) t2
on (t1.pid=t2.pid)
left join property_images t3 on (t2.minID=t3.id)
選擇哪一個是你的數據庫更快。
您需要選擇PID如果你有by子句 – Rocky 2012-08-15 07:19:56
把它列入你的小組謝謝raheel山 – Joyal 2012-08-15 07:23:40
謝謝洛基提醒我在趕時間較早公佈也 – 2012-08-15 07:35:14