2016-09-19 35 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