Helps to make a SQL query with the following conditions:?

Viewed 37

When making a query, I look for a field called "hashoriginal", when returning the result I need the search to return an empty search under the following conditions:

  1. if the value of the "date" field is greater than or equal to a predefined date (eg '2022-09-17'),
  2. and the value of the "hash" field is different from the one in the database.

Otherwise the query has to return the value that is in the database.

Getting these results I will complete my code in PHP

if (mysqli_num_rows($result_2) == 0)
{
    $query_update_mysql = mysqli_query($db_mysql, "UPDATE notas SET valornotas='{$valornotas_sqlite}',
    datacriacao='{$datacriacao_sqlite}', 
    descnota='{$descnota_sqlite}', 
    datasync='{$datasync_sqlite}', 
    hash= '{$hash_sqlite}' 
    WHERE hashoriginal = '$hashoriginal_sqlite';");
}

It updates the table only if it doesn't find anything in the search.

If it finds the result, the code jumps to the next record

SQL I tried

SELECT * from notes WHERE hashoriginal='3426F2485301DD89E89858F6BD3D359F'
and EXISTS(SELECT hash FROM notes WHERE hash = 'DC690251A78C118A41F686BF031600D39')
and not EXISTS(SELECT datasync FROM notes WHERE datasync>='2022-09-17')

But I'm not able to return the necessary conditions, can someone help me?

I use mysql 5.7.39 - MySQL Community Server (GPL)

0 Answers
Related