This wikiHow teaches you how to use the DISTINCT clause in SQL when you're working with more than one column. The DISTINCT clause allows you to eliminate rows that contain identical fields when using SELECT.

Steps

  1. 1
    Enter SELECT distinct and the names of each column. You can simply separate the column names with commas like this:
    • SELECT distinct column_1, column_2, column_3.
  2. 2
    Enter FROM table_name. Replace table_name with the name of the table, and then move to the next line.
    Advertisement
  3. 3
    Enter WHERE followed by the criteria. For example, if you want to display results based on the CODE field being 100, you'd enter:
    • WHERE code='100';
  4. 4
    Execute the command. You will now see only the distinct rows that that match your criteria.[1]
    Advertisement

About This Article

Nicole Levine, MFA
Co-authored by:
Tech Specialist
This article was co-authored by Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.
How helpful is this?
Co-authors: 4
Updated: March 5, 2021
Views: 785
Categories: Programming
Article SummaryX

To use the DISTINCT clause on multiple columns, use the syntax "SELECT distinct column_1, column_2, column_3." Each column name should be separated by a comma so they are recognized as separate columns.

Did this summary help you?
Advertisement