How to Select Distinct Data from Table in MySQL or MariaDB - MySQL Developer Tutorial

How to Select Distinct Data from Table in MySQL or MariaDB

When you use distinct keyword in Select, it returns you distinct (different) values.  Below is the syntax you will use to get distinct values from MySQL Table.


Select distinct column1,column2,... from YourTableName;


Example :
Let's create customer table and then insert some rows in customer table.

CREATE TABLE `customer` (
  `idcustomer` int,
  `firstname` varchar(50)  NULL,
  `lastname` varchar(30)  NULL,
  `age` int(11) DEFAULT NULL,
  `phonenumber` char(11) DEFAULT NULL,
  `dob` date DEFAULT NULL,
  `gender` char(1) NOT NULL
) ;



insert some values in table.

insert into customer(idcustomer,firstname,lastname,age,phonenumber,dob,gender)
values
(1,'Aamir','Ali',39,'505-4141969','1980-01-01','M'),
(2,'Aamir','Naz',39,'505-4141969','1980-01-01','M'),
(3,'Aamir','Shahzad',39,'505-4141900','1980-01-01','M');


Now let's say if you want to get the distinct or different values from first name column, you can run below  statement.


Select distinct firstname from customer;


The above query will return you only "Aamir".

Now let's say if you want to get distinct values for firstname and phonenumber, then you will get two values.


Select distinct firstname,phonenumber from customer;



34 comments:

  1. Computerized help has prepared it exaggeratedly. Would you be able to answer how it wound up conceivable? data science course in pune

    ReplyDelete
  2. Well, the most on top staying topic is Data Analytics. Data Analytics is one of the most promising technique in the growing world. I would like to add Data Analytics training to the preference list. Out of all, Data analytics course in Mumbai is making a huge difference all across the country. Thank you so much for showing your work and thank you so much for this wonderful article.

    ReplyDelete

  3. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. I would like to state about something which creates curiosity in knowing more about it. It is a part of our daily routine life which we usually don`t notice in all the things which turns the dreams in to real experiences. Back from the ages, we have been growing and world is evolving at a pace lying on the shoulder of technology. data science course will be a great piece added to the term technology. Cheer for more ideas & innovation which are part of evolution.

    ReplyDelete
  4. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    pmp certification in bangalore

    ReplyDelete
  5. Such a very useful article. I have learn some new information.thanks for sharing.
    data scientist course in mumbai

    ReplyDelete
  6. You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog.
    Data Analytics Course in Mumbai

    ReplyDelete
  7. Such a very useful Blog. Very interesting to read this article. I have learn some new information.thanks for sharing. know more about

    ReplyDelete
  8. Thanks for the informative and helpful post, obviously in your blog everything is good..
    ExcelR Data Analytics courses

    ReplyDelete
  9. Attend The PMP Certification From ExcelR. Practical PMP Certification Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The PMP Certification.
    ExcelR PMP Certification

    ReplyDelete
  10. Very nice blog here and thanks for post it.. Keep blogging...
    ExcelR data science training

    ReplyDelete
  11. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    ExcelR data science course in mumbai

    ReplyDelete
  12. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it. excelr data science

    ReplyDelete
  13. Great, i must say and thanks for sharing this informative post.I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, MyAssignmenthelp.com is giving help to students who is stressed with their homework help and submit their assignment on time.we are already trusted by thousands of students who struggle to write their academic papers and also by those students who simply want Cost of Capital Homework Help to save their time and make life easy

    ReplyDelete
  14. This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. Admond Lee

    ReplyDelete
  15. We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. Admond Lee

    ReplyDelete
  16. Very informative and well written post! Quite interesting and nice topic chosen for the post. My Assignment Help Au has been a pioneer within the Best Assignment Help on-line services and within the Australia and different countries ceaselessly for over Seven years. Make an order now for professional work, delivered on time and pure. You can email us at cs@Myassignmenthelpau.Com or Phone Number: +61-2-8005-8227.

    ReplyDelete
  17. When students help in online search they find the cost of essay writing very high. But at allassignmenthelp.com, we provide the best quality essays from students at low charge.
    best online essay writers

    professional college essay writers

    ReplyDelete
  18. To finish your project efficaciously, you must go for Assignment Help. services. How will you complete your assignment when you have no one to ask for help? Tough situation to deal with! This situation usually arises when students choose other countries to pursue their higher education especially the U.S.A. Getting the exact solution to your assignment related problem would not issue anymore. Browse our online portal and avail the best Online Assignment Help services as per your subject requirements.
    assignment help service
    assignment help company
    Help with assignment
    Help with assignment writing

    ReplyDelete
  19. Get best online Assignment help from top rated assignment help expert. We have 10+ years of experience in the field of assignment help. NZ Assignment Help are providing all the assignment help services for all college and university students. Our Assignment helpers NZ are giving on-time delivery guarantee with 100% plagiarism free content for all the assignment help.

    ReplyDelete
  20. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. analysis report

    ReplyDelete
  21. Singapore essay writing service are giving you headaches? If you are worried because of your assignment work and submit on time, then you have to select Singapore Assignment Help Writing Services from us and you can easily overcome such situations.

    ReplyDelete
  22. I know that it's not exactly your topic but I have a question. what is questionnaire writing? I need to complete this task. I look for some valuable ideas.

    ReplyDelete
  23. Assignment Help allows scholars to get professional assignment writers’ assistance for writing effective assignments and homework. Avail of reliable online assignment writing services to boost your marks through on-time project submission.
    Assignment Help Online
    Online Assignment Help
    Assignment Helper

    ReplyDelete
  24. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. If you're looking for CDR Report Help. You can email us at cs@needcdrreport.com or Phone Number: +61-2-8005-8227

    ReplyDelete
  25. You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog.
    ExcelR Courses in Business Analytics

    ReplyDelete
  26. My friend promised to buy me a cup of coffee for referring him to your site. Thank you for coffee. Kindly keep updating us on new articles. These days, the most common pump for a shallow well is a jet pump. Jet pumps get mounted above the well, either in the home or in a good house, and draw the water up from the well through suction. Visit Best Shallow Well Pump for more.

    ReplyDelete
  27. My friend advised me to pay for literature review. I am studying at college. We are always assignd different tasks. On of th recent is to write a literature review. I do not hav tim for writing that is why I would better buy it.

    ReplyDelete
  28. Getassignmenthelponline.com is the world’s best online assignment service provider. They do as they say on the time so you can take help with any academic consultation or Assignment Help . Our team is always ready to serve according to your needs at any given time. Mathematics Assignment Help Law Assignment Help

    ReplyDelete
  29. Thank you for bringing to a halt my long search topic. I really benefited from your content. If you are experiencing trouble striking a balance between your busy academic life and handling your online classes, you can get help from a professional who will take online classes on your behalf. It doesn’t matter the kind of help you need, whether it is passing your exam, finishing your assignments or even the entire classwork, you can get help here at Online Class Help .

    ReplyDelete
  30. The information provided on the site is informative. Looking forward more such blogs. Thanks for sharing .
    Artificial Inteligence course in Nashik
    AI Course in Nashik

    ReplyDelete
  31. Plumbers On Call provides best services for your queries with Plumbing Services Near Me. We are active all day to provide plumbers at your homes! Visit Plumbers On Call.

    ReplyDelete