Distinct result, display all columns












0















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?










share|improve this question









New contributor




user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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
    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
















0















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?










share|improve this question









New contributor




user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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
    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














0












0








0








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?










share|improve this question









New contributor




user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question









New contributor




user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 min ago







user175623













New contributor




user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









user175623user175623

1




1




New contributor




user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user175623 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • 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
    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



















  • 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
    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

















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
3 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
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





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










1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer
























  • 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













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.










draft saved

draft discarded


















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









0














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.






share|improve this answer
























  • 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


















0














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.






share|improve this answer
























  • 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
















0












0








0







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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












user175623 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

الفوسفات في المغرب

Four equal circles intersect: What is the area of the small shaded portion and its height

جامعة ليفربول