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. How to write

How to write

Scheduled Pinned Locked Moved Database
databasetutorial
4 Posts 4 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.
  • A Offline
    A Offline
    abglorie
    wrote on last edited by
    #1

    How to retrieve data from two different database with single query

    W G M 3 Replies Last reply
    0
    • A abglorie

      How to retrieve data from two different database with single query

      W Offline
      W Offline
      WoutL
      wrote on last edited by
      #2

      Put the database in teh from clause:

      select * from [database].[owner].[tablename]

      select * from nortwind.dbo.customers

      You can ommit the owner if you want:

      select * from northwind..customers

      Wout Louwers

      1 Reply Last reply
      0
      • A abglorie

        How to retrieve data from two different database with single query

        G Offline
        G Offline
        gajendra_kshatriya
        wrote on last edited by
        #3

        select t1.*,t2.* from database1name.dbo.tablename as t1 join database2name.dbo.tablename as t2 on t1.columnname=t2.columnname where condition (if any)

        1 Reply Last reply
        0
        • A abglorie

          How to retrieve data from two different database with single query

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          The responses you have assume that the databases are on the same server, in which case database.owner.tablename will work. If they are on different servers you have a problem, you need to set up linked servers, something I hate doing as the server is then hard coded into the query.

          Never underestimate the power of human stupidity RAH

          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