两个查询的不同值

时间:2015-08-26 11:23:28

标签: mysql

我需要过滤重复项,但是union正在显示重复项。

<m:FacetFilter
    id="idFacetFilter"
    type="Simple"
    showPersonalization="false"
    showReset="true"
    reset="onFacetFilterReset" 
    showPopoverOKButton="true">

    <m:lists>

        <m:FacetFilterList 
            title="{...}"
            key="{...}"
            multiselect="true"                  
            listClose="onFacetClosed"
            items="{...}" >

            <m:items>
                <m:FacetFilterItem
                    key="{...}"
                    text="{...}" />
            </m:items>
        </m:FacetFilterList>....

这是我的控制器:

For example Query-1 is displaying 5 tuples like 1,2,3,4,5.
Query-2 generating 3 tuples like 1,2,6.
Union of both the tuples displaying result 1,2,3,4,5,1,2,6.
But I want the result as 1,2,3,4,5,6.

2 个答案:

答案 0 :(得分:0)

没有明显的理由使用2个选择查询,第二个过滤器可以添加到现有的where子句

   SELECT * 
   FROM `product` 
   WHERE SOUNDEX(`name`) LIKE CONCAT('%',SOUNDEX('$temp[$i]'),'%')
   AND `name` like '%$temp[$i]%'";

答案 1 :(得分:-2)

首先,我可能会在另一种脚本语言中执行此操作,但如果您真的想在MySQL中执行此操作,则需要使用DISTINCT。您应该查询数据并将其放在临时表中,并从临时表中查询DISTINCT值。一旦完成,您可以删除临时表。对于一个小的操作,不确定这是否是我要做的,但如果你说你有数千个需要过滤的记录/值,那么它可能是值得的。

相关问题