SELECT returns nothing when I put a WHERE clause

Asked

Viewed 86 times

2

When I run the following sql command I get an empty return, even if I indicate an id that is present in some rows of the table to be searched

SELECT e.data_request,
       e.id_exchange,
       e.data_exchange,
       e.data_refound,
       s.description AS status,
       e.id_status,
       t.description AS type,
       u1.name AS requester,
       u2.name AS substitute,
       u3.name AS coord 
FROM exchanges AS e 
INNER JOIN status AS s ON e.id_status = s.id_status 
INNER JOIN users AS u1 ON e.requester = u1.id_user 
INNER JOIN users AS u2 ON e.substitute = u2.id_user 
INNER JOIN users AS u3 ON e.id_coord = u3.id_user 
INNER JOIN types AS t ON e.id_type = t.id_types 
WHERE e.id_coord = 1
OR e.id_rh = 1

In the database the following data are registered:

Table users:

inserir a descrição da imagem aqui


Table Exchanges:

inserir a descrição da imagem aqui


and this is the return I get when running SQL:

inserir a descrição da imagem aqui

  • In the WHERE clause, switch to WHERE (e. id_coord = 1 OR e.id_rh = 1)

  • received the same empty result making the change

  • removes the Where clause and checks how many Row appears

  • Ever tried to query only in the Exchanges table with Where to see if it returns, maybe it is the Inner’s that such using.

  • In your select you use the tables Exchanges, status, users and types but only showed the contents of the user and Exchanges tables. If the other tables do not matter it is that you actually want to use INNER JOIN in all of them or maybe you should use INNER JOIN only in these two and LEFT OUTER JOIN in the others?

1 answer

0

I was able to resolve with the help of a work friend, the error was in a registered item that was a FK, but the user record with the fk in question had been deleted. The solution was simply to place a FK Constraint into the id_coord field

Browser other questions tagged

You are not signed in. Login or sign up in order to post.