0

I have a database where I have two columns like you can see above. Note that the second line is equal to the first but the third is different as you can see

number_chip| Date_of_Scanned_chip
   345             2016-12-12
   345             2016-12-12
   345             2017-1-03 

The DISTINCT on the column (number_chip) eliminates all the chips and gives me only one

   number_chip| Date_of_Scanned_chip
       345             2016-12-12

But I want something that gives me this. Please help :)

number_chip| Date_of_Scanned_chip
       345             2016-12-12
       345             2017-1-03 //Eliminates the second line
3
  • DISTINCT applies to all the columns, not any particular one. Please provide a minimal reproducible example to demonstrate your problem. Commented Jan 6, 2017 at 20:58
  • Yes but I can have diferent number_chips with the same Date_of_Scanned_chip. As obvious I dont want to do a distinct in that date because in the table there are repetitive dates Commented Jan 6, 2017 at 21:01
  • You need to post the actual query, because SELECT DISTINCT should have done what you want. Commented Jan 6, 2017 at 21:12

2 Answers 2

2

The DISTINCT on the column (number_chip) eliminates all the chips and gives me only one

I cannot imagine what you mean by this. A simple query:

select distinct number_chip, Date_of_Scanned_chip
from t;

seems to do exactly what you want to do. select distinct is a statement in SQL. There is no distinct in SQL that operates on one column.

Sign up to request clarification or add additional context in comments.

2 Comments

I must have repetitive dates :/ because different chips can have equal scan_dates
@Jose This will do that. It only removes duplicates where both columns are the same.
-1

GROUP BY number_chip, Date_of_Scanned_chip;

1 Comment

When the columns in GROUP BY are the same as all the columns you're selecting, it's the same as SELECT DISTINCT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.