Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:55:07+00:00 2026-05-30T16:55:07+00:00

I got a problem in my query, that I think that can be resolved

  • 0

I got a problem in my query, that I think that can be resolved with a subselect.

I have a table called San_Proposta that has a primary key called Proposta_Id. In this table (San_Proposta) I have some columns, but a specific column is called StatusProposta_Id. StatusProposta_Id can only has 2 values: 1 or 2. If SanProposta_Id is 1, then the Proposta_Id don’t exists in a table called San_Negocio that has a foreign key called Proposta_Id. If StatusProposta_Id is 2, then the Proposta_Id exists in my table called San_Negocio.

In San_Negocio I have some columns, but let pay attention in 2 columns in specific: ValidaVenda and ValidaCaptacao. Both columns can only have 2 values: 1 or 0.

I want to do only one query that

  • returns all data that don’t exists in San_Negocio, (and how a told early, if San_Proposta.Proposta_Id is 1, then don’t exist in San_Negocio),
  • returns all data that exists in San_Proposta but not exists in San_Negocio (and how a told early, if San_Proposta.Proposta_Id is 2, then exists in San_Negocio)
  • If the San_Proposta.Proposta_Id exists on my table San_Negocio, (to Proposta_Id exists in my San_Negocio table, the San_Proposta.StatusProposta_Id has the value 2), my column called San_Negocio.ValidaVenda can’t has the same value of San_Negocio.ValidaCaptacao.

How can I do that ?

I tryied the follow query, but don’t work correctly

select 
   San_Proposta.Proposta_Id 
from 
   San_Proposta
left outer join 
     (
         select 
           * 
         from 
           San_Negocio 
         where 
           Proposta_Id is not null 
           and ValidaCaptacao <> ValidaVenda
     ) AS Negocio2
      on San_Proposta.Proposta_Id = Negocio2.Proposta_Id
where 
  San_Proposta.StatusProposta_Id IN (1,2)

@Updated

San_Proposta

Proposta_Id  |  StatusProposta_Id
1               1
2               1
3               1
4               2
5               2
6               2

San_Negocio

Proposta_Id  |  ValidaVenda  | ValidaCaptacao
4               1              0
5               0              1
6               1              1

@Updated

What I Expect

Proposta_Id
1
2
3
4
5

I want that the query returns Proposta_Id 1,2,3 (because don’t exist in San_Negocio) and Proposta_Id 4, 5 because they exist in San_Negocio but ValidaVenda is different then ValidaCaptacao.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:55:09+00:00Added an answer on May 30, 2026 at 4:55 pm
    select p.* from San_Proposta p 
    where p.StatusProposta_Id = 1
    
    union 
    
    select p.* from San_Proposta p 
        left join San_Negocio n on n.Proposta_Id = p.Proposta_Id
    where p.StatusProposta_Id = 2
        and n.ValidaCaptacao <> n.ValidaVenda
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got a problem with a query I'm trying to write. I have a table
I've got a Subsonic query that isn't returning any values. I think the problem
I've got a strange problem with SQL Server 2000, and I just can't think
I got a WCF service that has simple method called GetLineBusses. public MobileResponse GetLineBusses(MobileRequest
I've got a little problem with correct query and hope you can help me.
I got a problem with this linq query: from PersistedFileInfo fi in m_Database from
I have a query that I want to execute that fastest possible. Here it
I have an MS Access database that contains a table of dates, scores and
I've got a report that has been in use quite a while - in
I have a problem with the jquery ui button (I think). I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.