0

I am new to writing queries in SQL, and struggling to get the datas from table.

I have a table called "address" in DB. Here, I have more columns and specifically from two column I need to get the datas filtered out. Both are integers

  1. frequency_type_id
  2. date_of_invoice_id

    enter image description here

I need to get rows only where frequency_type_id = 1 and date_of_invoice_id=2, and frequency_type_id = 2 and date_of_invoice_id=3, frequency_type_id = 3 and date_of_invoice_id=1.

I am trying with the following query, but its not filtering properly,

SELECT address_id, company_name,  
invoice_batch_billing, frequency_type_id,  date_of_invoice_id
FROM pls.address where invoice_style='Consolidated' 
and frequency_type_id in 
(SELECT frequency_type_id from  pls.address where frequency_type_id=1 and date_of_invoice_id=1);

Hope someone assist.

2 Answers 2

1

Try below query:

SELECT address_id, company_name,  
invoice_batch_billing, frequency_type_id,  date_of_invoice_id
FROM pls.address where invoice_style='Consolidated' 
and ((frequency_type_id=1 and date_of_invoice_id=2) or (frequency_type_id=2 and date_of_invoice_id=2) or (frequency_type_id=3 and date_of_invoice_id=2))
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

SELECT 
    address_id, 
    company_name,
    invoice_batch_billing,
    frequency_type_id,
    date_of_invoice_id
FROM 
    pls.address
WHERE
    frequency_type_id IN (1,2,3) 
AND 
    date_of_invoice_id=2

If I have understand your question correctly, this will suffice your requirement.

1 Comment

Thanks Rahul. This is fine for same date_of_invoice_id. If there is change in the value of date_of_invoice_id like 1 for frequency_type_id. This works?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.