I want to create a nested query. I have a table named clicks with several columns among which are Datestamp, Keyword, Product_Title. The inner query is
SELECT DISTINCT(k.Keyword)
FROM clicks k
WHERE (k.Keyword LIKE '%word1%' AND k.Product_Title LIKE '%word2%');
Now I want to query for a bunch of rows such that the Keyword is one of the Keywords returned in the above query. I do the following:
SELECT c.Datestamp,c.Keyword,c.Product_Title
FROM clicks c
WHERE c.Keyword IN (
SELECT DISTINCT(k.Keyword)
FROM clicks k
WHERE (k.Keyword LIKE '%word1%' AND k.Product_Title LIKE '%word2%')
);
Simple as this might seem, it doesn't work. The query just hangs there. No error message, no feedback whatsoever, just hangs there. I don't have that many rows, about 300k, so I'm sure the issue isn't the table being too big.
Suggestions?
ANDin yourWHERE-Condition? The way you posted it here, there won't ever be a result because it's always false.distinctis not a functiondistinctworks.distinct (col1), col2is the same asdistinct col1, col2ordistinct (col1, col2).distinctalways operates on all columns in the select list and the parentheses will not change that behaviour.