Query to return one id for all unique combinations of four columns

dobseh

Member
Local time
Today, 17:07
Joined
Jul 9, 2022
Messages
47
I have a table with some data that looks like the below screenshot. I'm trying to work out a way of returning one s_id for each unique combination of discount_lookup, abilitiy_level_lookup, payment_installments and weekly_sessions. I've put red dots next to the s_id's that the query should return on the screenshot, but it doesn't actually matter whether the s_id returned is the lowest numbered one for each combinations. 1,1,1,1 could return s_id 14292(as indicated), but 14407 would be equally acceptable. The query is for exception testing on another process that is run against this data.

I'd be grateful for any help/pointers on the best way to do this, so thanks in advance!

query.JPG
 
Rather important, how do you want to choose "14292" instead of "14407"?
XPS35 has already given an answer that will work, but make sure you understand how you need to choose your S_ID an have that logic written down. It will avoid massive headaches later when your query doesn't match to what someone else expects.
 
Rather important, how do you want to choose "14292" instead of "14407"?
XPS35 has already given an answer that will work, but make sure you understand how you need to choose your S_ID an have that logic written down. It will avoid massive headaches later when your query doesn't match to what someone else expects.
It doesn't matter which for the purposes of this. It's just for testing a process without running the entire thing over many, many records and then having to manually check each combination got spat out as it should. Nobody else gets the pleasure of seeing the data apart from me, it's not an end user thing.
 

Users who are viewing this thread

Back
Top Bottom