How to return an SQL with result?

Asked

Viewed 108 times

1

I need to select several tables linked by the "user id" and return the data to compose a profile page, but some of these tables may be empty at first, that is, the query will not find the "user id" in one of them and will return an error or no data. How can I select multiple tables by returning the query regardless of the data found or not?

inserir a descrição da imagem aqui

1 answer

2


I have an example of a similar situation I went through. Voce must use the left join:

SELECT PERMISSAO.Codigo CODIGO,
       PERMISSAO.Descricao DESCRICAO,
       ISNULL(permissaoUsuario.acesso, 'N') ACESSO
  FROM permissao 
  LEFT JOIN permissaoUsuario ON PERMISSAO.Codigo = permissaoUsuario.codpermisao
   AND permissaoUsuario.codusuario = @CODUSUARIO
 WHERE PERMISSAO.DATAEXCLUSAO IS NULL

In this example I used the left join (bring from left) to bring the table permissions PERMISSAO even if the record is not inserted in the table PERMISSAOUSUARIO

Browser other questions tagged

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