Re: Combine results based on a value



On Feb 22, 4:38 pm, "aravind.ka...@xxxxxxxxx"
<aravind.ka...@xxxxxxxxx> wrote:
I need to join two tables where when the join condition is true, it
should return YES and returns NO if it doesnt. Let me try to give an
example:

I have BOOK_RENTALS which contains customer names and books:

JOHN SMITH, BOOKA
JOHN SMITH, BOOKB
JOHN SMITH, BOOKC

and I have a Book Master:

BOOKA
BOOKB
BOOKC
BOOKD
BOOKE

I would like to combine the results from these two tables such that I
get results as follows:

JOHN SMITH, BOOKA, YES
JOHN SMITH, BOOKB, YES
JOHN SMITH, BOOKC, YES
JOHN SMITH, BOOKD, NO
JOHN SMITH, BOOKE, NO

Is this possible in a single sql statement?

Any help is appreciated.

You might try doing this with an outer join (left outer join), and
then use the DECODE or NVL2 function on the BOOK_RENTALS.BOOK column
to determine what to return when that column is NULL.

Left outer join syntax:
WHERE
TABLE1.COLUMN1 = TABLE2.COLUMN1(+)

There should be plenty of examples in this group and through a Google
search to help with the DECODE and/or NVL2 syntax.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.
.



Relevant Pages

  • Re: Better way to sum 0 entries?
    ... I originally thought of this Tom, but the outer join should also include the ... > where b.LibraryID = l.LibraryID) as Books ... > LibraryID INTEGER, ...
    (microsoft.public.sqlserver.programming)
  • Re: Verifying a Date from previous record before allowing new reco
    ... "Jeff Boyce" wrote: ... I am creating a database to keep track of books being checked out. ... Date_Checked_In field being populated for John Smith. ... Update on the first field in the Subform to check for the Date_Checked_In ...
    (microsoft.public.access.formscoding)
  • Re: Verifying a Date from previous record before allowing new record a
    ... If you have two tables, you may need to rethink your data design. ... I am creating a database to keep track of books being checked out. ... Date_Checked_In field being populated for John Smith. ... Update on the first field in the Subform to check for the Date_Checked_In ...
    (microsoft.public.access.formscoding)
  • Re: Busy Day -- Incarville text
    ... If you are interested in books like that you can download some old ... John Smith wrote: ... allegedly the first Western account that details fireworks-making in China. ...
    (rec.pyrotechnics)
  • Re: K&R2 Still good?
    ... John Smith said: ... great majority of it understandable and useful. ... and Peter Jackson to dive straight into such books, ...
    (comp.lang.c)