5
I have a table with columns para
and de
where I enter different Ids in each one, but I need to get the ID of the user who SENT the request to me, ie the ID that is not the same as the logged in user.
SELECT `username` FROM all, users WHERE (`de` = 'ID DO USUARIO LOGADO' OR `para` = 'ID DO USUARIO LOGADO') AND (users.idu = chat.from NOT IN (ID DO USUARIO LOGADO) OR users.idu = chat.to NOT IN (ID DO USUARIO LOGADO)) GROUP BY `c_id` order by id desc
Dai created this code, but it continues to return me the ID of the logged-in user and not of what sent, which occurs?
I used the NOT IN
to prevent it from being logged in user ID, it still didn’t work.
Exemplo:
Tabela ALL
-------------
| de | para |
-------------
| 2 | 1 |
-------------
TABELA USERS
------------------
| idu | username |
------------------
| 1 | MARCOS |
------------------
| 2 | MANUEL |
------------------
SELECIONA O ROW ONDE (para = USUARIO LOGADO or de = USUARIO LOGADO) e depois vai na tabela USERS e seleciona o usuário que não seja o usuário logado dentre `para` e `de`.
Ou Seja, retornaria -> Manuel
What are the structures of your tables? It would be good also some sample data. I have a little difficulty in understanding your query, that column
username
is on which table?– mgibsonbr
@mgibsonbr Atualizei, it is clear I hope.
– Vinícius Lara