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. search from multiple tables

search from multiple tables

Scheduled Pinned Locked Moved Database
databasequestion
8 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.
  • T Offline
    T Offline
    test 09
    wrote on last edited by
    #1

    Hi all, This is how im getting columns from 3 tables....

    select projectID=projects.projectid,projectname,
    [image],country,county,ClientCompany,city,ConstructionCompletionDate_dt,
    OverallBuildingSize_uts from projects, schedule,BuildingSiteStatics
    where projects.projectid=schedule.projectid and projects.projectid=BuildingSiteStatics.projectid

    I have searched from 2 tables using following query

    select a.*,b.ConstructionCompletionDate_dt from projects a join
    schedule b on a.projectid=b.projectid where projectname like '%%' or
    country like '' or clientcompany like '%%' or
    ConstructionCompletionDate_dt like '%%'

    Now i need to search columns from 5 tables How can i do it....

    W M L 3 Replies Last reply
    0
    • T test 09

      Hi all, This is how im getting columns from 3 tables....

      select projectID=projects.projectid,projectname,
      [image],country,county,ClientCompany,city,ConstructionCompletionDate_dt,
      OverallBuildingSize_uts from projects, schedule,BuildingSiteStatics
      where projects.projectid=schedule.projectid and projects.projectid=BuildingSiteStatics.projectid

      I have searched from 2 tables using following query

      select a.*,b.ConstructionCompletionDate_dt from projects a join
      schedule b on a.projectid=b.projectid where projectname like '%%' or
      country like '' or clientcompany like '%%' or
      ConstructionCompletionDate_dt like '%%'

      Now i need to search columns from 5 tables How can i do it....

      W Offline
      W Offline
      www Developerof NET
      wrote on last edited by
      #2

      test-09 wrote:

      Now i need to search columns from 5 tables How can i do it....

      Obviously, you need to join the remaining tables with your existing ones and filter the data from the corresponding columns.

      When you fail to plan, you are planning to fail.

      1 Reply Last reply
      0
      • T test 09

        Hi all, This is how im getting columns from 3 tables....

        select projectID=projects.projectid,projectname,
        [image],country,county,ClientCompany,city,ConstructionCompletionDate_dt,
        OverallBuildingSize_uts from projects, schedule,BuildingSiteStatics
        where projects.projectid=schedule.projectid and projects.projectid=BuildingSiteStatics.projectid

        I have searched from 2 tables using following query

        select a.*,b.ConstructionCompletionDate_dt from projects a join
        schedule b on a.projectid=b.projectid where projectname like '%%' or
        country like '' or clientcompany like '%%' or
        ConstructionCompletionDate_dt like '%%'

        Now i need to search columns from 5 tables How can i do it....

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

        As said, jion all 5 tables. If you expect to reuse the 5 table join in other queries I would create a view, makes life much simpler.

        Never underestimate the power of human stupidity RAH

        T 1 Reply Last reply
        0
        • M Mycroft Holmes

          As said, jion all 5 tables. If you expect to reuse the 5 table join in other queries I would create a view, makes life much simpler.

          Never underestimate the power of human stupidity RAH

          T Offline
          T Offline
          test 09
          wrote on last edited by
          #4

          select projectID=projects.projectid,projectname,
          [image],country,county,ClientCompany,city,ConstructionCompletionDate_dt,
          OverallBuildingSize_uts from projects, schedule,BuildingSiteStatics
          where projects.projectid=schedule.projectid and projects.projectid=BuildingSiteStatics.projectid

          using above query how can i join 5 tables..

          M 1 Reply Last reply
          0
          • T test 09

            select projectID=projects.projectid,projectname,
            [image],country,county,ClientCompany,city,ConstructionCompletionDate_dt,
            OverallBuildingSize_uts from projects, schedule,BuildingSiteStatics
            where projects.projectid=schedule.projectid and projects.projectid=BuildingSiteStatics.projectid

            using above query how can i join 5 tables..

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

            This query uses what I call Oracle joins where the links are in the where clause, never to be seen in any database I own. Use the propert join methods. Here is a sample from a view I have

            FROM dbo.FactConsoTB AS F
            INNER JOIN dbo.Branch AS B ON F.BranchID = B.BranchID
            INNER JOIN dbo.lnkAccountProduct AS L ON F.APLinkID = L.APLinkID
            INNER JOIN dbo.Account AS A ON L.AccountID = A.AccountID
            INNER JOIN dbo.Product AS P ON L.ProductID = P.ProductID
            INNER JOIN dbo.Currency AS C ON F.CurrencyID = C.CurrencyID
            INNER JOIN dbo.Currency AS BC ON F.BaseCurrencyID = BC.CurrencyID
            INNER JOIN dbo.ProductCategory ON P.ProductCategoryID = dbo.ProductCategory.ProductCategoryID

            test-09 wrote:

            select projectID=projects.projectid

            Why are you useing this.

            Never underestimate the power of human stupidity RAH

            T 1 Reply Last reply
            0
            • M Mycroft Holmes

              This query uses what I call Oracle joins where the links are in the where clause, never to be seen in any database I own. Use the propert join methods. Here is a sample from a view I have

              FROM dbo.FactConsoTB AS F
              INNER JOIN dbo.Branch AS B ON F.BranchID = B.BranchID
              INNER JOIN dbo.lnkAccountProduct AS L ON F.APLinkID = L.APLinkID
              INNER JOIN dbo.Account AS A ON L.AccountID = A.AccountID
              INNER JOIN dbo.Product AS P ON L.ProductID = P.ProductID
              INNER JOIN dbo.Currency AS C ON F.CurrencyID = C.CurrencyID
              INNER JOIN dbo.Currency AS BC ON F.BaseCurrencyID = BC.CurrencyID
              INNER JOIN dbo.ProductCategory ON P.ProductCategoryID = dbo.ProductCategory.ProductCategoryID

              test-09 wrote:

              select projectID=projects.projectid

              Why are you useing this.

              Never underestimate the power of human stupidity RAH

              T Offline
              T Offline
              test 09
              wrote on last edited by
              #6

              using view i tried this but im getting error "Ambiguous column name 'ConstructionCompletionDate_dt'" what wrong im doing....

              SELECT dbo.Projects.ProjectID, dbo.Projects.ProjectName,
              dbo.Projects.City, dbo.Projects.County, dbo.Projects.Country,
              dbo.Projects.ClientCompany,
              dbo.BuildingSiteStatics.OverallBuildingSize_uts,
              dbo.Schedule.ConstructionCompletionDate_dt,
              dbo.OverallDevelopment.TotalNumberDwellings

              FROM dbo.Projects INNER JOIN
              dbo.BuildingSiteStatics ON dbo.Projects.ProjectID = dbo.BuildingSiteStatics.ProjectID INNER JOIN

                                dbo.OverallDevelopment ON dbo.Projects.ProjectID
              

              = dbo.OverallDevelopment.ProjectID INNER JOIN

                                dbo.Schedule ON dbo.Projects.ProjectID = dbo.Schedule.ProjectID where projectname like '%%' or country like ''
              

              or clientcompany like '%%' or ConstructionCompletionDate_dt like '%%'

              M 1 Reply Last reply
              0
              • T test 09

                using view i tried this but im getting error "Ambiguous column name 'ConstructionCompletionDate_dt'" what wrong im doing....

                SELECT dbo.Projects.ProjectID, dbo.Projects.ProjectName,
                dbo.Projects.City, dbo.Projects.County, dbo.Projects.Country,
                dbo.Projects.ClientCompany,
                dbo.BuildingSiteStatics.OverallBuildingSize_uts,
                dbo.Schedule.ConstructionCompletionDate_dt,
                dbo.OverallDevelopment.TotalNumberDwellings

                FROM dbo.Projects INNER JOIN
                dbo.BuildingSiteStatics ON dbo.Projects.ProjectID = dbo.BuildingSiteStatics.ProjectID INNER JOIN

                                  dbo.OverallDevelopment ON dbo.Projects.ProjectID
                

                = dbo.OverallDevelopment.ProjectID INNER JOIN

                                  dbo.Schedule ON dbo.Projects.ProjectID = dbo.Schedule.ProjectID where projectname like '%%' or country like ''
                

                or clientcompany like '%%' or ConstructionCompletionDate_dt like '%%'

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

                Prefix the column name with the tablename or the alias. Also try Google and BOL, the response time is generally quicker and gentler.

                Never underestimate the power of human stupidity RAH

                1 Reply Last reply
                0
                • T test 09

                  Hi all, This is how im getting columns from 3 tables....

                  select projectID=projects.projectid,projectname,
                  [image],country,county,ClientCompany,city,ConstructionCompletionDate_dt,
                  OverallBuildingSize_uts from projects, schedule,BuildingSiteStatics
                  where projects.projectid=schedule.projectid and projects.projectid=BuildingSiteStatics.projectid

                  I have searched from 2 tables using following query

                  select a.*,b.ConstructionCompletionDate_dt from projects a join
                  schedule b on a.projectid=b.projectid where projectname like '%%' or
                  country like '' or clientcompany like '%%' or
                  ConstructionCompletionDate_dt like '%%'

                  Now i need to search columns from 5 tables How can i do it....

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  test-09 wrote:

                  Now i need to search columns from 5 tables How can i do it....

                  One alternative would be to build some views, consisting of a tablename, columnname and a varchar representing the value. Create a union of those views to search all columns with a single select-statement and the LIKE operator. What database are you using? If you're on Sql Express, have you considered using the Full Text Search[^] component?

                  I are Troll :suss:

                  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