Distinct result, display all columns
Suppose there are fields of Username, Logon, Roles, etc, etc
I want to query and display all fields, but username's output should be distinct
(select distinct(username), *)
What is the most accurate query?
query
New contributor
add a comment |
Suppose there are fields of Username, Logon, Roles, etc, etc
I want to query and display all fields, but username's output should be distinct
(select distinct(username), *)
What is the most accurate query?
query
New contributor
What have you tried? Is username a unique or primary key? If not why not?
– danblack
4 hours ago
1
You need to provide more information here. If username should be distinct, but there are duplicate values in this column, how will you aggregate the data in other columns that varies? If it is already unique, then you don't need to do a distinct. Sample table schema, data and expected results will help get you assistance too.
– HandyD
4 hours ago
Username is PK. I only want username's output to be distinct. I am not worried about the display of other columns (logon, roles, etc). For example, select distinct(username), * from table where logon='today' and roles='admin'
– user175623
3 hours ago
A primary key by definition is unique. There is no need for a distinct anything, your username is unique no matter how you query it.
– danblack
2 hours ago
add a comment |
Suppose there are fields of Username, Logon, Roles, etc, etc
I want to query and display all fields, but username's output should be distinct
(select distinct(username), *)
What is the most accurate query?
query
New contributor
Suppose there are fields of Username, Logon, Roles, etc, etc
I want to query and display all fields, but username's output should be distinct
(select distinct(username), *)
What is the most accurate query?
query
query
New contributor
New contributor
edited 15 mins ago
user175623
New contributor
asked 4 hours ago
user175623user175623
6
6
New contributor
New contributor
What have you tried? Is username a unique or primary key? If not why not?
– danblack
4 hours ago
1
You need to provide more information here. If username should be distinct, but there are duplicate values in this column, how will you aggregate the data in other columns that varies? If it is already unique, then you don't need to do a distinct. Sample table schema, data and expected results will help get you assistance too.
– HandyD
4 hours ago
Username is PK. I only want username's output to be distinct. I am not worried about the display of other columns (logon, roles, etc). For example, select distinct(username), * from table where logon='today' and roles='admin'
– user175623
3 hours ago
A primary key by definition is unique. There is no need for a distinct anything, your username is unique no matter how you query it.
– danblack
2 hours ago
add a comment |
What have you tried? Is username a unique or primary key? If not why not?
– danblack
4 hours ago
1
You need to provide more information here. If username should be distinct, but there are duplicate values in this column, how will you aggregate the data in other columns that varies? If it is already unique, then you don't need to do a distinct. Sample table schema, data and expected results will help get you assistance too.
– HandyD
4 hours ago
Username is PK. I only want username's output to be distinct. I am not worried about the display of other columns (logon, roles, etc). For example, select distinct(username), * from table where logon='today' and roles='admin'
– user175623
3 hours ago
A primary key by definition is unique. There is no need for a distinct anything, your username is unique no matter how you query it.
– danblack
2 hours ago
What have you tried? Is username a unique or primary key? If not why not?
– danblack
4 hours ago
What have you tried? Is username a unique or primary key? If not why not?
– danblack
4 hours ago
1
1
You need to provide more information here. If username should be distinct, but there are duplicate values in this column, how will you aggregate the data in other columns that varies? If it is already unique, then you don't need to do a distinct. Sample table schema, data and expected results will help get you assistance too.
– HandyD
4 hours ago
You need to provide more information here. If username should be distinct, but there are duplicate values in this column, how will you aggregate the data in other columns that varies? If it is already unique, then you don't need to do a distinct. Sample table schema, data and expected results will help get you assistance too.
– HandyD
4 hours ago
Username is PK. I only want username's output to be distinct. I am not worried about the display of other columns (logon, roles, etc). For example, select distinct(username), * from table where logon='today' and roles='admin'
– user175623
3 hours ago
Username is PK. I only want username's output to be distinct. I am not worried about the display of other columns (logon, roles, etc). For example, select distinct(username), * from table where logon='today' and roles='admin'
– user175623
3 hours ago
A primary key by definition is unique. There is no need for a distinct anything, your username is unique no matter how you query it.
– danblack
2 hours ago
A primary key by definition is unique. There is no need for a distinct anything, your username is unique no matter how you query it.
– danblack
2 hours ago
add a comment |
1 Answer
1
active
oldest
votes
With username being a primary key of table;
select username,{otherfields} from table where logon='today'
will only every have a unique username in the output.
Put your sample data, table structures and example data in the question WHEN YOU FIRST ASK IT. Edit the question and add it clearly formatted now! Try not to contradict yourself. You said username is the PK which obviously isn't the case if there are duplicates. Use a dbfiddle. See Why SELECT * is considered harmful
– danblack
1 hour ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
user175623 is a new contributor. Be nice, and check out our Code of Conduct.
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%2fdba.stackexchange.com%2fquestions%2f233195%2fdistinct-result-display-all-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
With username being a primary key of table;
select username,{otherfields} from table where logon='today'
will only every have a unique username in the output.
Put your sample data, table structures and example data in the question WHEN YOU FIRST ASK IT. Edit the question and add it clearly formatted now! Try not to contradict yourself. You said username is the PK which obviously isn't the case if there are duplicates. Use a dbfiddle. See Why SELECT * is considered harmful
– danblack
1 hour ago
add a comment |
With username being a primary key of table;
select username,{otherfields} from table where logon='today'
will only every have a unique username in the output.
Put your sample data, table structures and example data in the question WHEN YOU FIRST ASK IT. Edit the question and add it clearly formatted now! Try not to contradict yourself. You said username is the PK which obviously isn't the case if there are duplicates. Use a dbfiddle. See Why SELECT * is considered harmful
– danblack
1 hour ago
add a comment |
With username being a primary key of table;
select username,{otherfields} from table where logon='today'
will only every have a unique username in the output.
With username being a primary key of table;
select username,{otherfields} from table where logon='today'
will only every have a unique username in the output.
answered 2 hours ago
danblackdanblack
2,1161214
2,1161214
Put your sample data, table structures and example data in the question WHEN YOU FIRST ASK IT. Edit the question and add it clearly formatted now! Try not to contradict yourself. You said username is the PK which obviously isn't the case if there are duplicates. Use a dbfiddle. See Why SELECT * is considered harmful
– danblack
1 hour ago
add a comment |
Put your sample data, table structures and example data in the question WHEN YOU FIRST ASK IT. Edit the question and add it clearly formatted now! Try not to contradict yourself. You said username is the PK which obviously isn't the case if there are duplicates. Use a dbfiddle. See Why SELECT * is considered harmful
– danblack
1 hour ago
Put your sample data, table structures and example data in the question WHEN YOU FIRST ASK IT. Edit the question and add it clearly formatted now! Try not to contradict yourself. You said username is the PK which obviously isn't the case if there are duplicates. Use a dbfiddle. See Why SELECT * is considered harmful
– danblack
1 hour ago
Put your sample data, table structures and example data in the question WHEN YOU FIRST ASK IT. Edit the question and add it clearly formatted now! Try not to contradict yourself. You said username is the PK which obviously isn't the case if there are duplicates. Use a dbfiddle. See Why SELECT * is considered harmful
– danblack
1 hour ago
add a comment |
user175623 is a new contributor. Be nice, and check out our Code of Conduct.
user175623 is a new contributor. Be nice, and check out our Code of Conduct.
user175623 is a new contributor. Be nice, and check out our Code of Conduct.
user175623 is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Database Administrators Stack Exchange!
- 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%2fdba.stackexchange.com%2fquestions%2f233195%2fdistinct-result-display-all-columns%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
What have you tried? Is username a unique or primary key? If not why not?
– danblack
4 hours ago
1
You need to provide more information here. If username should be distinct, but there are duplicate values in this column, how will you aggregate the data in other columns that varies? If it is already unique, then you don't need to do a distinct. Sample table schema, data and expected results will help get you assistance too.
– HandyD
4 hours ago
Username is PK. I only want username's output to be distinct. I am not worried about the display of other columns (logon, roles, etc). For example, select distinct(username), * from table where logon='today' and roles='admin'
– user175623
3 hours ago
A primary key by definition is unique. There is no need for a distinct anything, your username is unique no matter how you query it.
– danblack
2 hours ago