Questions tagged as 'sql'

1
answer

Filter data in sql

I have a clientes table with columns: nome cidade email1 email2 It's not all customers who have registered with email. How do I mount a sql statement where it only returns clients containing email1 or email2 ?...
asked by 23.04.2018 / 15:41
1
answer

ERROR 1215: Can not add foreign key constraint (MySQL Workbench)

Hello, I'm trying to add a foreign key to a table but I get error 1215. I've already checked the attributes and all are compatible, the wallet field is a primary key, I do not understand why it's not possible to add the key. ALTER TABL...
asked by 18.04.2018 / 08:41
1
answer

Consider NULL as 0

In the following query I need the transaction_value to be considered 0 when it is NULL in the highlighted aggregation, how can it be done? I tried using it but it did not work SELECT num_empenho AS EMP, data_empenho AS DATA, nome_fornecedor AS...
asked by 18.04.2018 / 19:37
1
answer

Compare values using SQL

I find myself in the following picture situation I need via sql to compare the value of the property with the minimum and maximum filter value but due to the semicolons I do not get results. How can I fix this?     
asked by 13.04.2018 / 16:23
1
answer

How to sort the result of a query by a column where there is a value in another column in the same table?

I have a table with several columns, and I want to sort the results by the values of one of the columns where another column in the same table is equal to a value. I have already tried to implement the query with CASE , IF's and...
asked by 18.05.2018 / 16:52
1
answer

I'm having some problems with GROUP BY

I'm having a hard time putting together a select with GROUP BY . What I want to do is this: I have three tables: bicos idbico, idempresa, idbomba abastecimentos idabastec, idbico, idempresa, valora...
asked by 18.05.2018 / 21:20
1
answer

SQL returning error when selecting nonexistent field

It has a system that several companies use, but the changes in the bank tables are not informed. I would like to create a select that would not return an error when it did not find a field recently taken from a table? Code: SELECT c...
asked by 04.05.2018 / 16:49
1
answer

Select to get 2 columns constraint

I have a PERSON table that has field A and B that form a UNIQUE . I squeeze this select to return the name of the constraint : SELECT DISTINCT COL.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab, INFORMATION_SCHEMA...
asked by 06.04.2018 / 20:29
1
answer

Update a query in installment form

Good afternoon, today a small question has arisen. Somewhere in my code I have a query to do an update. The function is as follows: function updateUser(user_id, params) { const query = 'UPDATE users SET user_name...
asked by 12.04.2018 / 18:30
1
answer

PostgreSQL query bringing more results than expected

Hello, I have a situation in a system where I need to find out which student enrollments are related to a tutor in a class. The tables I have are: matricula containing foreign key with student (mat_aln_id) and with class (mat_tur_...
asked by 10.04.2018 / 15:38