help with sql - join query Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: help with sql - join query

  1. #1
    Join Date
    Feb 2000
    regarding the following sql:

    SELECT a.lname, a.fname, a.user_id, c.address,,, c.addresstypeid, d.descriptor as state
    FROM users a, address c, maintstatetype d
    WHERE a.user_id = c.user_id(+)
    AND c.statetypeid = d.statetypeid(+)
    AND c.addresstypeid in (1,2)

    I have a database of users and addresses. Each user can have multiple addresses and the addresses are designated by addresstypeid. In plain english, what I want to pull is "If they have an addresstypeid of 2, use that, if not, use addresstypeid of 1".

    Any help with this?

  2. #2
    Join Date
    Sep 2001
    Makati, Philippines
    include decode in your select staetement:

    select decode(c.addresstypeid,2,c.address2,c.address) address, a.lname, ......, blah, blah.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width