1
Suppose the T1 table is:
id nome data_cadastro
1 joão 09/07/2017
2 maria 10/07/2017
and table T2 is:
id t1_id data_sistema
1 1 09/07/2017
2 1 10/07/2017
When you do:
SELECT T1.* FROM CONSULTAS T1, PARAMETROS T2
WHERE (T1.DATA_CADASTRO <= T2.DATA_SISTEMA-14)
the amount of records returned is the product between the rows of the two tables. In this specific query there would be four (the correct one would be at most 2 which is the maximum number of records in each table). In this query is made the combination of the rows of the two tables involved.
To avoid the situation described above, one must relate the two tables in some way. In the example there is a relation indicated by the foreign key t1_id in table T2. Putting this relation in the query is:
SELECT T1.* FROM CONSULTAS T1, PARAMETROS T2
WHERE T1.id = T2.t1_id and (T1.DATA_CADASTRO <= T2.DATA_SISTEMA-14)
You could have been more specific in your question! What function the entity (table) queries and parameters specify these relationships which are the primary keys. If there is a relationship key the correct one was to use JOIN for that query!
– Rafael Salomão
What’s wrong with using the distinct? the items will be repeated as often as they appear within the table parameters, put the structure of the tables and what the purpose of the query so that we can help
– Rovann Linhalis
You would have to be more specific in the question. You would need to show what is in your tables, if possible.
– Rafael Weber
Then if there is no other way I will use the distinct...
– Edu Mendonça
The only relation between the two tables is the date?
– Jefferson Quesado