SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    display data with full address, if there is any null values present?

    Hi all,

    I have two tables with columns as;

    in table1;

    empno,ename,address1,address2,address3,city,state

    in table2;

    empno,ename,address11,address22,address33,city,state

    Now i want to write a query as,

    to display the table1 data with full address, if there is any null values present in table1 in address (address1,address2,address3) columns, i want to fetch that row address (address11,address22,address33) columns from table2 for that corresponding row based on the empno and display at a time.

    Please give me an idea to resolve this problem soon.

    Thanking you.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    for "corresponding row" you will need to do a JOIN

    if table2 row always exists for corresponding table1 row, use an INNER JOIN

    then use COALESCE function so that, for example, if address1 is null, it returns address11
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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