I have these table from a database. The table WORKER has 2 fields one of them is ID_W(number) and the other is DUTY(text).
I want to create an sql query that selects only ID_W(id of worker) which have the same DUTY where DUTY is a text type field.
Can someone help me? I want to use an aggregate function but none of them helps.
If I am understanding your question correctly, you are looking for only the IDs of the workers whose DUTY field matches that of another worker.
You can do this with a WHERE EXISTS clause, but you need to CONVERT the TEXT column into a VARCHAR (MAX) in order to compare them. This conversion on both sides will make the query expensive, but this is another way to do it:
From WORKER A
From WORKER B
Where A.ID_W <> B.ID_W
And Convert(Varchar (Max), A.DUTY) = Convert(Varchar (Max), B.DUTY)
Asked in February 2016Viewed 2,634 timesVoted 6Answered 2 times