Select from Multiple Tables

  • I have to get data for a set of columns every month from 30 different tables. The data is to be stored datewise. The data are stored in a particular table named -- 'lonYYYYMMDD' where YYYYMMDD stands for the date to which the data pertains to.

    My job is to get data in the following format:

    Date

  • That sound like a pretty insane table design. What's wrong with storing all the data in one table with a date column? 

    That said... The union statement (and union all) is your friend here

    SELECT <columns> FROM TableForDateA

    UNION ALL

    SELECT <columns> FROM TableForDateB

    UNION ALL

    SELECT <columns> FROM TableForDateC

    ...

    Look up Union in Books online for the specifics of how it works. If you need more help, please post your table design, sample data and required output.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply