Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining two queries

Status
Not open for further replies.

ofsouto

Programmer
Apr 29, 2000
185
BR
Is it possible to join these two queries in only one query?
If the first query returns a null value I need get the value from the 2nd query.

SELECT MIN(A.CODE) FROM TABLE_A A, TABLE_B B
WHERE A.VALUE >= B.VALUE

SELECT MAX(A.CODE) FROM TABLE_A A, TABLE_B B
WHERE A.VALUE < B.VALUE

Thanks in advance.
 
SELECT MIN(A.CODE) FROM TABLE_A A, TABLE_B B
WHERE A.VALUE >= B.VALUE
[red]Union [all][/red]
SELECT MAX(A.CODE) FROM TABLE_A A, TABLE_B B
WHERE A.VALUE < B.VALUE
 
Code:
SELECT
  ISNULL
  (
    (
      SELECT 
        MIN(A.CODE) 
      FROM 
        TABLE_A A, TABLE_B B
      WHERE 
        A.VALUE >= B.VALUE  
    ),
    (
      SELECT 
        MAX(A.CODE) 
      FROM 
        TABLE_A A, TABLE_B B
      WHERE 
        A.VALUE < B.VALUE
    (
  )

“I apologize for this long letter. I didn't have the time to make it any shorter” --Blaise Pascal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top