Get unique values from Oracle SQL
I have a table data with have 100.000 rows+ and its content like below;
Service Owner
ABC JOHN
ABC MARK
ABC MARK
ABC STEVE
ABC STEVE
The output what i want is like below. Only getting unique values for services;
Service Owner
ABC JOHN
ABC MARK
ABC STEVE
How can i select the query?
sql oracle
add a comment |
I have a table data with have 100.000 rows+ and its content like below;
Service Owner
ABC JOHN
ABC MARK
ABC MARK
ABC STEVE
ABC STEVE
The output what i want is like below. Only getting unique values for services;
Service Owner
ABC JOHN
ABC MARK
ABC STEVE
How can i select the query?
sql oracle
Please explain your logic.
– Gordon Linoff
Nov 13 '18 at 19:03
I edited the question.
– john true
Nov 13 '18 at 19:05
add a comment |
I have a table data with have 100.000 rows+ and its content like below;
Service Owner
ABC JOHN
ABC MARK
ABC MARK
ABC STEVE
ABC STEVE
The output what i want is like below. Only getting unique values for services;
Service Owner
ABC JOHN
ABC MARK
ABC STEVE
How can i select the query?
sql oracle
I have a table data with have 100.000 rows+ and its content like below;
Service Owner
ABC JOHN
ABC MARK
ABC MARK
ABC STEVE
ABC STEVE
The output what i want is like below. Only getting unique values for services;
Service Owner
ABC JOHN
ABC MARK
ABC STEVE
How can i select the query?
sql oracle
sql oracle
edited Nov 13 '18 at 19:05
john true
asked Nov 13 '18 at 19:03
john truejohn true
10211
10211
Please explain your logic.
– Gordon Linoff
Nov 13 '18 at 19:03
I edited the question.
– john true
Nov 13 '18 at 19:05
add a comment |
Please explain your logic.
– Gordon Linoff
Nov 13 '18 at 19:03
I edited the question.
– john true
Nov 13 '18 at 19:05
Please explain your logic.
– Gordon Linoff
Nov 13 '18 at 19:03
Please explain your logic.
– Gordon Linoff
Nov 13 '18 at 19:03
I edited the question.
– john true
Nov 13 '18 at 19:05
I edited the question.
– john true
Nov 13 '18 at 19:05
add a comment |
2 Answers
2
active
oldest
votes
An aggregate query should do the trick:
SELECT MIN(service), owner
FROM mytable
GROUP BY owner
your answer and above answer gives me different rows count
– john true
Nov 13 '18 at 19:09
the other answer have more rows.
– john true
Nov 13 '18 at 19:18
This would work for the sample data and give the expected output. It sounds like you have rows where one owner has multiple services. If that is the case and you would like to see all unique services tied to the owner, you should go with theselect distinct
answer.
– Patrick H
Nov 13 '18 at 19:58
add a comment |
Selecting the distinct service and owner will give you the unique combinations of service and owner.
SELECT DISTINCT service,owner FROM TABLE
Here's a SQLFiddle.
Why? Help out by explaining -a bit- why does it solve OP's question
– Alfabravo
Nov 13 '18 at 19:06
@Alfabravo - Done!
– dcp
Nov 13 '18 at 19:08
your answer and below answer gives me different rows count.
– john true
Nov 13 '18 at 19:09
@john true - Added a SQLFiddle, which is producing the output you listed in your question.
– dcp
Nov 13 '18 at 19:17
@john what exactly is the correct row count?
– Salman A
Nov 13 '18 at 19:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287867%2fget-unique-values-from-oracle-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
An aggregate query should do the trick:
SELECT MIN(service), owner
FROM mytable
GROUP BY owner
your answer and above answer gives me different rows count
– john true
Nov 13 '18 at 19:09
the other answer have more rows.
– john true
Nov 13 '18 at 19:18
This would work for the sample data and give the expected output. It sounds like you have rows where one owner has multiple services. If that is the case and you would like to see all unique services tied to the owner, you should go with theselect distinct
answer.
– Patrick H
Nov 13 '18 at 19:58
add a comment |
An aggregate query should do the trick:
SELECT MIN(service), owner
FROM mytable
GROUP BY owner
your answer and above answer gives me different rows count
– john true
Nov 13 '18 at 19:09
the other answer have more rows.
– john true
Nov 13 '18 at 19:18
This would work for the sample data and give the expected output. It sounds like you have rows where one owner has multiple services. If that is the case and you would like to see all unique services tied to the owner, you should go with theselect distinct
answer.
– Patrick H
Nov 13 '18 at 19:58
add a comment |
An aggregate query should do the trick:
SELECT MIN(service), owner
FROM mytable
GROUP BY owner
An aggregate query should do the trick:
SELECT MIN(service), owner
FROM mytable
GROUP BY owner
answered Nov 13 '18 at 19:06
MureinikMureinik
181k22131200
181k22131200
your answer and above answer gives me different rows count
– john true
Nov 13 '18 at 19:09
the other answer have more rows.
– john true
Nov 13 '18 at 19:18
This would work for the sample data and give the expected output. It sounds like you have rows where one owner has multiple services. If that is the case and you would like to see all unique services tied to the owner, you should go with theselect distinct
answer.
– Patrick H
Nov 13 '18 at 19:58
add a comment |
your answer and above answer gives me different rows count
– john true
Nov 13 '18 at 19:09
the other answer have more rows.
– john true
Nov 13 '18 at 19:18
This would work for the sample data and give the expected output. It sounds like you have rows where one owner has multiple services. If that is the case and you would like to see all unique services tied to the owner, you should go with theselect distinct
answer.
– Patrick H
Nov 13 '18 at 19:58
your answer and above answer gives me different rows count
– john true
Nov 13 '18 at 19:09
your answer and above answer gives me different rows count
– john true
Nov 13 '18 at 19:09
the other answer have more rows.
– john true
Nov 13 '18 at 19:18
the other answer have more rows.
– john true
Nov 13 '18 at 19:18
This would work for the sample data and give the expected output. It sounds like you have rows where one owner has multiple services. If that is the case and you would like to see all unique services tied to the owner, you should go with the
select distinct
answer.– Patrick H
Nov 13 '18 at 19:58
This would work for the sample data and give the expected output. It sounds like you have rows where one owner has multiple services. If that is the case and you would like to see all unique services tied to the owner, you should go with the
select distinct
answer.– Patrick H
Nov 13 '18 at 19:58
add a comment |
Selecting the distinct service and owner will give you the unique combinations of service and owner.
SELECT DISTINCT service,owner FROM TABLE
Here's a SQLFiddle.
Why? Help out by explaining -a bit- why does it solve OP's question
– Alfabravo
Nov 13 '18 at 19:06
@Alfabravo - Done!
– dcp
Nov 13 '18 at 19:08
your answer and below answer gives me different rows count.
– john true
Nov 13 '18 at 19:09
@john true - Added a SQLFiddle, which is producing the output you listed in your question.
– dcp
Nov 13 '18 at 19:17
@john what exactly is the correct row count?
– Salman A
Nov 13 '18 at 19:39
add a comment |
Selecting the distinct service and owner will give you the unique combinations of service and owner.
SELECT DISTINCT service,owner FROM TABLE
Here's a SQLFiddle.
Why? Help out by explaining -a bit- why does it solve OP's question
– Alfabravo
Nov 13 '18 at 19:06
@Alfabravo - Done!
– dcp
Nov 13 '18 at 19:08
your answer and below answer gives me different rows count.
– john true
Nov 13 '18 at 19:09
@john true - Added a SQLFiddle, which is producing the output you listed in your question.
– dcp
Nov 13 '18 at 19:17
@john what exactly is the correct row count?
– Salman A
Nov 13 '18 at 19:39
add a comment |
Selecting the distinct service and owner will give you the unique combinations of service and owner.
SELECT DISTINCT service,owner FROM TABLE
Here's a SQLFiddle.
Selecting the distinct service and owner will give you the unique combinations of service and owner.
SELECT DISTINCT service,owner FROM TABLE
Here's a SQLFiddle.
edited Nov 13 '18 at 19:17
answered Nov 13 '18 at 19:06
dcpdcp
42.8k16119146
42.8k16119146
Why? Help out by explaining -a bit- why does it solve OP's question
– Alfabravo
Nov 13 '18 at 19:06
@Alfabravo - Done!
– dcp
Nov 13 '18 at 19:08
your answer and below answer gives me different rows count.
– john true
Nov 13 '18 at 19:09
@john true - Added a SQLFiddle, which is producing the output you listed in your question.
– dcp
Nov 13 '18 at 19:17
@john what exactly is the correct row count?
– Salman A
Nov 13 '18 at 19:39
add a comment |
Why? Help out by explaining -a bit- why does it solve OP's question
– Alfabravo
Nov 13 '18 at 19:06
@Alfabravo - Done!
– dcp
Nov 13 '18 at 19:08
your answer and below answer gives me different rows count.
– john true
Nov 13 '18 at 19:09
@john true - Added a SQLFiddle, which is producing the output you listed in your question.
– dcp
Nov 13 '18 at 19:17
@john what exactly is the correct row count?
– Salman A
Nov 13 '18 at 19:39
Why? Help out by explaining -a bit- why does it solve OP's question
– Alfabravo
Nov 13 '18 at 19:06
Why? Help out by explaining -a bit- why does it solve OP's question
– Alfabravo
Nov 13 '18 at 19:06
@Alfabravo - Done!
– dcp
Nov 13 '18 at 19:08
@Alfabravo - Done!
– dcp
Nov 13 '18 at 19:08
your answer and below answer gives me different rows count.
– john true
Nov 13 '18 at 19:09
your answer and below answer gives me different rows count.
– john true
Nov 13 '18 at 19:09
@john true - Added a SQLFiddle, which is producing the output you listed in your question.
– dcp
Nov 13 '18 at 19:17
@john true - Added a SQLFiddle, which is producing the output you listed in your question.
– dcp
Nov 13 '18 at 19:17
@john what exactly is the correct row count?
– Salman A
Nov 13 '18 at 19:39
@john what exactly is the correct row count?
– Salman A
Nov 13 '18 at 19:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287867%2fget-unique-values-from-oracle-sql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please explain your logic.
– Gordon Linoff
Nov 13 '18 at 19:03
I edited the question.
– john true
Nov 13 '18 at 19:05