Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. is these two queries same?

is these two queries same?

Scheduled Pinned Locked Moved Database
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dhyanga
    wrote on last edited by
    #1

    Hi all, Is there any difference between the following two sets of queries?

    select a.ID_NUM as ID, b.LAST_NAME, b.FIRST_NAME, c.BIRTH_DTE, RIGHT(c.SSN, 4),
    a.RESIDSTS, d.ROOM_DESC, d.ROOM_PHONE
    from SMASTER a
    join NMASTER b on a.ID_NUM = b.ID_NUM
    join BMASTER c on a.ID_NUM = c.ID_NUM
    join RMASTER d on a.LOC_CDE = d.LOC_CDE and a.BLDG_CDE = d.BLDG_CDE and a.ROOM_CDE = d.ROOM_CDE
    where LOWER(b.LAST_NAME) like '%ram%'
    and a.RESIDSTS = 'R' and (a.T_CDE in ('20', '21') or a.UDEF in ('20', '21'))
    UNION
    select a.ID_NUM as ID, b.LAST_NAME, b.FIRST_NAME, c.BIRTH_DTE, RIGHT(c.SSN, 4),
    a.RESIDSTS as STATUS, '' , ''
    from SMASTER a
    join NMASTER b on a.ID_NUM = b.ID_NUM
    join BMASTER c on a.ID_NUM = c.ID_NUM
    join RMASTER d on a.ID_NUM = a.ID_NUM
    where LOWER(b.LAST_NAME) like '%ram%'
    and a.RESIDSTS <> 'R' and (a.T_CDE in ('20', '21') or a.UDEF in ('20', '21'))

    and

    select a.ID_NUM as ID, b.LAST_NAME, b.FIRST_NAME, c.BIRTH_DTE, RIGHT(c.SSN, 4),
    a.RESIDSTS, d.ROOM_DESC, d.ROOM_PHONE
    from SMASTER a
    join NMASTER b on a.ID_NUM = b.ID_NUM
    join BMASTER c on a.ID_NUM = c.ID_NUM
    join RMASTER d on a.LOC_CDE = d.LOC_CDE and a.BLDG_CDE = d.BLDG_CDE and a.ROOM_CDE = d.ROOM_CDE
    where LOWER(b.LAST_NAME) like '%ram%'
    and (a.RESIDSTS = 'R' or a.RESIDSTS <> 'R') and (a.T_CDE in ('20', '21') or a.UDEF in ('20', '21'))

    well in one there is "UNION" used but will there any difference in the output or are these both queries same as per the output is concered?

    suchita

    J 1 Reply Last reply
    0
    • D Dhyanga

      Hi all, Is there any difference between the following two sets of queries?

      select a.ID_NUM as ID, b.LAST_NAME, b.FIRST_NAME, c.BIRTH_DTE, RIGHT(c.SSN, 4),
      a.RESIDSTS, d.ROOM_DESC, d.ROOM_PHONE
      from SMASTER a
      join NMASTER b on a.ID_NUM = b.ID_NUM
      join BMASTER c on a.ID_NUM = c.ID_NUM
      join RMASTER d on a.LOC_CDE = d.LOC_CDE and a.BLDG_CDE = d.BLDG_CDE and a.ROOM_CDE = d.ROOM_CDE
      where LOWER(b.LAST_NAME) like '%ram%'
      and a.RESIDSTS = 'R' and (a.T_CDE in ('20', '21') or a.UDEF in ('20', '21'))
      UNION
      select a.ID_NUM as ID, b.LAST_NAME, b.FIRST_NAME, c.BIRTH_DTE, RIGHT(c.SSN, 4),
      a.RESIDSTS as STATUS, '' , ''
      from SMASTER a
      join NMASTER b on a.ID_NUM = b.ID_NUM
      join BMASTER c on a.ID_NUM = c.ID_NUM
      join RMASTER d on a.ID_NUM = a.ID_NUM
      where LOWER(b.LAST_NAME) like '%ram%'
      and a.RESIDSTS <> 'R' and (a.T_CDE in ('20', '21') or a.UDEF in ('20', '21'))

      and

      select a.ID_NUM as ID, b.LAST_NAME, b.FIRST_NAME, c.BIRTH_DTE, RIGHT(c.SSN, 4),
      a.RESIDSTS, d.ROOM_DESC, d.ROOM_PHONE
      from SMASTER a
      join NMASTER b on a.ID_NUM = b.ID_NUM
      join BMASTER c on a.ID_NUM = c.ID_NUM
      join RMASTER d on a.LOC_CDE = d.LOC_CDE and a.BLDG_CDE = d.BLDG_CDE and a.ROOM_CDE = d.ROOM_CDE
      where LOWER(b.LAST_NAME) like '%ram%'
      and (a.RESIDSTS = 'R' or a.RESIDSTS <> 'R') and (a.T_CDE in ('20', '21') or a.UDEF in ('20', '21'))

      well in one there is "UNION" used but will there any difference in the output or are these both queries same as per the output is concered?

      suchita

      J Offline
      J Offline
      JV9999
      wrote on last edited by
      #2

      Yes, those should give the same result. They might be a bit different sorted I think, but in the end the same data should be in the output. Edit: I oversaw one small thing. The second query in the union doesn't return the values of d.ROOM_DESC, d.ROOM_PHONE, but rather two empty strings in those columns. In your combined query these columns will be filled.

      D 1 Reply Last reply
      0
      • J JV9999

        Yes, those should give the same result. They might be a bit different sorted I think, but in the end the same data should be in the output. Edit: I oversaw one small thing. The second query in the union doesn't return the values of d.ROOM_DESC, d.ROOM_PHONE, but rather two empty strings in those columns. In your combined query these columns will be filled.

        D Offline
        D Offline
        Dhyanga
        wrote on last edited by
        #3

        ya thank you..

        suchita

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups