• 0
Sign in to follow this  
sreletronica

consulta 2 tabelas if existe id na segunda aparece preço se não aparece preço da primeira tabela

Question

boa noite, pessoal, preciso de ajuda em uma consulta 2 tabelas if existe id na segunda aparece preço se não aparece preço da primeira tabela..

exemplo

 

tabela1                                                                                        tabela2

------------------------------------                 --------------------------------------------------------

id                | descricao            | preço                      id           |           dtini      |       dtfim                    | preço

17               | pao de sal           | 9,00                         20         |   26/10/2017 | 30/10/2017              | 1,99

18               | bolo                      | 10,80                     17          | 26/10/2017  | 10/11/2017               | 6,10  

20               | Quiabo                 | 2,99

23               | Tomate                | 3,50

 

 

de modo que quando execultar a consulta resulte desta forma

 

tabela1                                                                                                                                            

------------------------------------------------------------------------                    

id                | descricao                                                 | preço                                                          

17               | pao de sal                                                | 6,10                                                             

18               | bolo                                                           | 10,80                                                          

20               | Quiabo                                                      | 1,99

23               | Tomate                                                     | 3,50

 

de modo que vou dar um select na tabela1 e listar tudo mas se a id existir na tabela2 pregar o preço da tabela2, se não existir manter o preço da tabela1..

 

Quem puder ajudar...

 

pode ser em postgres, fb,, mysql..

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this