My guess is that you want to specify the particular columns and use distinct
(or group by
):
SELECT DISTINCT operator, cnic, station
FROM USER_LOGIN INNER JOIN
STATION
ON USER_LOGIN.S_ID = STATION.S_ID INNER JOIN
POST
ON USER_LOGIN.USER_ID = POST.USER_ID INNER JOIN
ROLE
ON USER_LOGIN.ROLE_ID = ROLE.ROLE_ID
WHERE ROLE_NAME = 'Operator';
EDIT:
If you want one arbitrary row, then do something like this:
SELECT *
FROM (SELECT POST.*, USER_LOGIN.*, STATION.*, ROLE.*,
row_number() over (partition by operator, cnic, station order by operator) as seqnum
FROM USER_LOGIN INNER JOIN
STATION
ON USER_LOGIN.S_ID = STATION.S_ID INNER JOIN
POST
ON USER_LOGIN.USER_ID = POST.USER_ID INNER JOIN
ROLE
ON USER_LOGIN.ROLE_ID = ROLE.ROLE_ID
WHERE ROLE_NAME = 'Operator'
) t
WHERE seqnum = 1;
The row_number()
function enumerates rows in groups. Each group starts over at 1. The grouping is defined by partition by
, so rows with the same value of operator
, cnic
, and station
will be in a grouping. The order by
specifies the order of the numbers within a group. Here is uses a constant for the group, so it is arbitrary. The final step is where seqnum = 1
, which chooses one row from each grouping.