#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    6
    Rep Power
    0

    Distinct values across 2 tables


    Hi all. will try to explain this as simply as possible :

    i have a table named "casetypes" with a field "name";

    i have another table called "legacyCasetypes" with a field "casetype";


    i want to populate a dropdown list to have all of the values from the casetypes table, AS WELL AS all unique values from legacy casetypes. so in pseudo code, i want something like :

    select distinct casetypes from legacyCasetypes, name from casetypes, combine them as "dropdownValues" into new table

    or maybe there's a better mechanism, but essentially i want a laundry list of all current casetypes and all old ones still in the old table, all in one dropdown.

    don't need to know how to dynamically populate the dropdown, can do that already, i just need help with the SQL statement to paste together the data i want

    help?
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,140
    Rep Power
    4274
    Code:
    SELECT casetype AS dropdownValues
      FROM legacyCasetypes
    UNION
    SELECT name 
      FROM casetypes
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    6
    Rep Power
    0

    perfect


    thanks a million Rudy, worked like a charm. you are definitely "the man". elegant and simple solution. thanks bud.

IMN logo majestic logo threadwatch logo seochat tools logo