I have a table with dimensions called measures. The table has one column for the location and a second column for the corresponding value (the example is simplified).
The table looks like (note the 2 entries for loc1):
location | value ----------------- loc1 | value1 loc1 | value2 loc2 | value3 loc3 | value4 loc4 | value5
Now I want to formulate an SQL query (I actually use sqlite) that returns only the first two rows of the table (i.e., loc + value1 and loc1 + value2), because this location contains more than one record in this table.
the wording of the pseudo-text will be: show me rows of locations that are present more than once in the whole table
pseudo code:
SELECT * from measures WHERE COUNT(location over the whole table) > 1
The solution may be really simple, but somehow I do not seem to have cracked the nut.
that I am still a SELECT statement that returns locations with more than one record. as the next step, I will need exactly all the rows corresponding to the locations returned from this query:
SELECT location FROM measures GROUP BY location HAVING count(*) > 1
so in the next step I tried to make a JOIN with the same table and include the query above, but the results are incorrect. I tried this, but this is wrong:
select t1.location, t1.value from measures as t1 join measures as t2 on t1.location = t2.location group by t2.location having count(*) > 1
help is appreciated!
source share