Selecting rows but disregarding repetition of cell values

Joshua Galang

I have a table of customers that has repetition of first names and last names. I don't know what type of select query should I use to display specific row regarding their same entries.

Example: Table: customers

customer_id|firstname|lastname
-----------+---------+---------
0000000001 |Peter    |Griffin
0000000002 |Peter    |Pan
0000000003 |Mary     |Magdalene
0000000003 |Mary     |Jane

And the output I want is like is:

customer_id|firstname|lastname
-----------+---------+---------
0000000001 |Peter    |Griffin
0000000003 |Mary     |Magdalene

I know this is easy but I'm new to SQL.

Erwin Brandstetter

One way to do this is with DISTINCT ON:

SELECT DISTINCT ON (firstname)
       customer_id, firstname, lastname 
FROM   customers
ORDER  BY firstname, customer_id;

See:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Userform and Selecting Cell values

Selecting rows until empty cell

Selecting cell when values match

Selecting rows with unique column values

Selecting rows with specific values in a column

Selecting values from pandas rows

How to get the total sum of counted values separated by commas in multiple rows, but disregarding zeroes?

Selecting a specific number of rows, from a given cell

Selecting rows by members of a list contained in a cell

Split values in cell into columns and rows

Pandas Skip rows on cell values

Separate multiple cell values to rows

Selecting values between two columns in multiple rows

Delete duplicated rows, selecting specific values to retain

Selecting Rows based on multiple values in column

selecting the rows based on the distinct column values

MySQL - selecting rows with some values being null

selecting rows with min and max values in pandas dataframe

Selecting dataframe rows based on values in other dataframe

Pandas pivot table selecting rows with maximum values

Selecting rows from a dataframe using a list of values

Selecting multiple rows based on different column values

Selecting rows with shared values in two distinct fields

Selecting different rows with same id but different values

Selecting a subset of rows that exceed a percentage of total values

Selecting the rows with unique values after filtering duplicates

R: Selecting Rows based on values in multiple columns

Selecting rows with the most repeated values at specific column

Selecting a single rows based on two columns values