2016-09-19 24 views
-1

我在此獲取多個單個屬性的行,因爲我已經離開了聯接property_image表,並且它包含多個具有相同屬性的圖像。設置在查看的sql聯接聲明中的限制

CREATE OR REPLACE VIEW Basic 
AS 
SELECT 
    crawlproperty_images.image_name as property_image 
FROM crawl_properties 
    LEFT JOIN crawlproperty_images 
    ON (crawl_properties.id=crawlproperty_images.crawl_property_id) 
+1

問題是? – jarlh

+1

編輯你的問題,並提供樣本數據和預期結果。 –

回答

0

返回您在SQL-SERVER的第一行:

CREATE OR REPLACE VIEW Basic 
AS 
SELECT TOP 1 
crawlproperty_images.image_name as property_image FROM crawl_properties 
LEFT JOIN crawlproperty_images ON (crawl_properties.id=crawlproperty_images.crawl_property_id) 

返回你在MySQL中的第一行:

CREATE OR REPLACE VIEW Basic 
AS 
SELECT 
crawlproperty_images.image_name as property_image FROM crawl_properties 
LEFT JOIN crawlproperty_images ON (crawl_properties.id=crawlproperty_images.crawl_property_id) 
LIMIT 1 
+0

'TOP 1'不是MYSQL語法 – RiggsFolly

+0

@riggsFolly正確。 Thx注意 – Nebi

0

你可以在MySQL中使用LIMIT如下:

CREATE OR REPLACE VIEW Basic 
AS 
SELECT crawlproperty_images.image_name AS property_image 
FROM crawl_properties 
LEFT JOIN crawlproperty_images ON (crawl_properties.id=crawlproperty_images.crawl_property_id) 
LIMIT 1 
0

你不能把李在加入。但是你可以在查詢結尾處使用限制。

例如, select * from table t1 left join table t2 on t1.id = t2.id limit 10