0

I currently use the following to pull data for today from my database:

select TheTime, Thename, theplace from Stats where Selection = "SIR" and Thedata > 19.99 and DATE(TheTime)  = CURDATE() 

The field TheTime is a DateTime field. I would like to check if any duplicate times are in this field. If there are then remove them all from the select query.

I am only looking for results that have 1 distinct DateTime. I have tried to use select DISTINCT TheTime but it still pulled the non-distanct values.

6
  • What version your MySQL is? Commented Jul 25, 2019 at 14:32
  • 10.2.25-MariaDB-cll-lve Commented Jul 25, 2019 at 14:34
  • Those column names though. Commented Jul 25, 2019 at 14:37
  • Selection = "SIR" Make a habit out of it writing strings values in SQL with single quotes.. in the ANSI/ISO SQL standard double quotes means identifiers meaning columns and or table names.. Commented Jul 25, 2019 at 14:42
  • @RaymondNijland thanks for the tip! Commented Jul 25, 2019 at 14:46

2 Answers 2

1

I have tried the following query on my database:

SELECT DISTINCT createdOn FROM tbldata

The createdOn is DATETIME data element with CURRENT_TIMESTAMP default expression. The query returns distinct values. My server version is 8.0.15, InnoDB engine

Be advised that

In MariaDB, the DISTINCT clause doesn't ignore NULL values. So when using the DISTINCT clause in your SQL statement, your result set will include NULL as a distinct value.

https://www.techonthenet.com/mariadb/distinct.php

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

1 Comment

"In MariaDB, the DISTINCT clause doesn't ignore NULL values. So when using the DISTINCT clause in your SQL statement, your result set will include NULL as a distinct value." Wierd statement i think we found our new w3fools as it sounds like DISTINCT in ANSI/ISO SQL standards is designed to ignore NULL values..
0

Try GROUP BY TheTime.

SELECT DISTINCT is working with keys so you would have to use TheTime as key to make it work.

1 Comment

GROUP BY TheTime will still give me 1 result depeding on order by would it not?

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.