I’m trying to write a query that returns me the selected rows of the columns based on x and y row values of another column.
But the following query is returning me all the rows of the two selected columns even though I’ve specified a range. Could anyone please tell me what’s wrong I’m doing?
select username, password
from loginuser
group by username, password
having count(id) between '1' and '2'
The
HAVINGoperator is to be applied to aggregate functions – if you want to pick those rows where aSUMexceeds a certain value or something.You just want a regular selection – use a
WHEREclause for that:This will select all rows where the value of
IDis between 1 and 2.If you want to select by row number, ordered by ID – you need something like this:
If you don’t have any
SUMorCOUNTin your query, you shouldn’t be using aGROUP BYeither…Is that what you’re looking for?? Based on your question and query, it’s not entirely clear what you’re really looking for…. can you describe in more detail what you want to select’?