Question

J'ai une table simple avec deux colonnes (bien deux colonnes d'intérêt, plus simplement une pièce d'identité) ... je recherche une ajax qui est juste à la recherche des mots-clés ... qui sont ensuite envoyés à ma vraie recherche .. . la recherche ajax ne se soucie pas ce qu'ils sont, mais ils doivent être distincts ...

Comment puis-je fusionner les deux colonnes ensemble:

City, Country

Krakow, Poland
Warsaw, Poland
Austin, USA
New York, USA
Prague, Czech Republic

Alors que je recevrais

Keyword, Sideinfo

Krakow, Poland
Warsaw, Poland
Austin, USA
Prague, Czech Republic
USA, Country (only once)
Poland, Country
Czech Republic, Country

J'ai essayé de faire une UNION, mais je ne sais pas comment je ferais WHERE LIKE « % mot-clé »

L'espoir qui fait sens ...

Était-ce utile?

La solution

Essayez ceci.

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%'

Autres conseils

Cela devrait le faire:

select distinct country Keyword,'Country' SideInfo from Cities
union all
select City Keyword,Country SideInfo from Cities
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top