我有一个查询,该查询使用三个查找表来获取我需要的所有信息。我需要DISTINCT
为一列提供值,但是我还需要与之关联的其余数据。
我的SQL代码:
SELECT acss_lookup.ID AS acss_lookupID,
acss_lookup.product_lookupID AS acssproduct_lookupID,
acss_lookup.region_lookupID AS acssregion_lookupID,
acss_lookup.document_lookupID AS acssdocument_lookupID,
product.ID AS product_ID,
product.parent_productID AS productparent_product_ID,
product.label AS product_label,
product.displayheading AS product_displayheading,
product.displayorder AS product_displayorder,
product.display AS product_display,
product.ignorenewupdate AS product_ignorenewupdate,
product.directlink AS product_directlink,
product.directlinkURL AS product_directlinkURL,
product.shortdescription AS product_shortdescription,
product.logo AS product_logo,
product.thumbnail AS product_thumbnail,
product.content AS product_content,
product.pdf AS product_pdf,
product.language_lookupID AS product_language_lookupID,
document.ID AS document_ID,
document.shortdescription AS document_shortdescription,
document.language_lookupID AS document_language_lookupID,
document.document_note AS document_document_note,
document.displayheading AS document_displayheading
FROM acss_lookup
INNER JOIN product ON (acss_lookup.product_lookupID = product.ID)
INNER JOIN document ON (acss_lookup.document_lookupID = document.ID)
ORDER BY product_displayheading ASC;
我想从该查询中获取所有产品,但我只想获取一次,因为我正在填充搜索应用程序的下拉菜单。我希望用户能够从该表中的产品中进行选择(这就是为什么我只需要它们一次的原因)。
这太复杂了吗?我应该使用更简化的方法吗?
但是产品与许多文档有关。您的查询将它们全部返回(产品文档)。应该选择哪一个?
—
–ypercubeᵀᴹ2012年