Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5958991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:37:20+00:00 2026-05-22T18:37:20+00:00

SELECT DISTINCT field1, field2, field3, …… FROM table; I am trying to accomplish the

  • 0
SELECT DISTINCT field1, field2, field3, ......
FROM table;

I am trying to accomplish the following SQL statement, but I want it to return all columns.
Is this possible?

Something like this:

SELECT DISTINCT field1, * 
FROM table;
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:37:22+00:00Added an answer on May 22, 2026 at 6:37 pm

    You’re looking for a group by:

    select *
    from table
    group by field1
    

    Which can occasionally be written with a distinct on statement:

    select distinct on field1 *
    from table
    

    On most platforms, however, neither of the above will work because the behavior on the other columns is unspecified. (The first works in MySQL, if that’s what you’re using.)

    You could fetch the distinct fields and stick to picking a single arbitrary row each time.

    On some platforms (e.g. PostgreSQL, Oracle, T-SQL) this can be done directly using window functions:

    select *
    from (
       select *,
              row_number() over (partition by field1 order by field2) as row_number
       from table
       ) as rows
    where row_number = 1
    

    On others (MySQL, SQLite), you’ll need to write subqueries that will make you join the entire table with itself (example), so not recommended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query working: SELECT DISTINCT table1.field1, table1.field2 FROM table1 WHERE table1.field3
I'm trying to do the following in MySQL: SELECT DISTINCT field FROM table WHERE
consider the following pgSQL statement: SELECT DISTINCT some_field FROM some_table WHERE some_field LIKE 'text%'
Whats the difference between SELECT DISTINCT field1 FROM table1 cd JOIN table2 ON cd.Company
The following query: SELECT DISTINCT ClassName FROM SiteTree ORDER BY ClassName is returning things
In this function, its default value all is never returned: $grid->setSelect(title, SELECT DISTINCT field1,field2
I'm trying to get the following query to work in Hibernate: SELECT m FROM
I'm trying to select distinct substring values of a field and count the number
SELECT DISTINCT group_id , supplier_id , supplier_name , site_division_id , site_division_name FROM view_supplier_site WHERE
SELECT DISTINCT wposts.* FROM wp_2_posts wposts, wp_2_postmeta wpostmeta, wp_2_postmeta wpostmeta1, wp_2_term_taxonomy, wp_2_terms, wp_2_term_relationships WHERE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.