我有一个简单的表,有两列(两列感兴趣,只有一个ID)...我有一个ajax搜索,只是寻找关键字...然后发送到我的真实搜索.. ajax搜索不关心它们是什么,但它们需要区别......
如何将两列合并在一起:
City, Country
Krakow, Poland
Warsaw, Poland
Austin, USA
New York, USA
Prague, Czech Republic
所以我会得到
Keyword, Sideinfo
Krakow, Poland
Warsaw, Poland
Austin, USA
Prague, Czech Republic
USA, Country (only once)
Poland, Country
Czech Republic, Country
我试过做一个UNION,但我不确定我怎么做'WHERE LIKE'关键字''
希望有道理......
答案 0 :(得分:1)
试试这个。
SELECT Keyword, SideInfo
FROM
(
SELECT
DISTINT City as Keyword, Country as SideInfo
FROM Table
UNION
SELECT
DISTINCT Country, 'Country'
FROM Table
) AS InnerQuery
Where Keyword LIKE '%blah%'
答案 1 :(得分:0)
这应该这样做:
select distinct country Keyword,'Country' SideInfo from Cities
union all
select City Keyword,Country SideInfo from Cities