This might be confusing but what I want to do is a basic select distinct columnx limit 3, the problem I have is it returns 3 rows, but I only want to get all values from one distinct columnx.
id|columnx
1 |here
2 |here
3 |Idontwant
4 |Apple
so I want a query that will return 1 and 2. The problem is columnx could be anything and I cant just say where columnx = ‘here’
The limit 3 comes into play because it’s hard coded into my C# app. The issue is i also set a hashset based on columnx, i have to have that columnx static for all records. However, with every query i put together there is the possibility that with my limit i’ll return 2 values in columnx, which are distinct values however, i can only have distinct columnx value per query.
No what I want is all values that belong to columnx, in this example columnx =’here’, when i do a distinct all I want back is the first distinct result, not ‘Idontwant’ or ‘apple’ regardless of the limit.
Here is the query and it works.
SELECT id,columnx
FROM sites where columnx= (select distinct columnx from sites limit 1) limit 3
It sounds like you want the id values for three distinct columnx values. Is this right? Try this:
I also wonder if you need some ORDER BY in there somewhere, but your question doesn’t mention that, so I’ve omitted it–essentially meaning that you’ll get three semi-random columnx values.