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. selecting from 3 different tables

selecting from 3 different tables

Scheduled Pinned Locked Moved Database
databasesaleshelpquestion
5 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.
  • R Offline
    R Offline
    regin
    wrote on last edited by
    #1

    im a begginer,i have 3 different tables [customer,invoice,projects] Customer table intcid[PK] Companyname ProjectTable intprojectId[PK], intCid[FK], strName , startdate, Invoice Table intinvoiceId[PK] intCid[FK] intProjectId[FK] monTotal i want to select these tables based on the Project name i give.. if the project doesnt have invoice also i have show the output as null in the corresponing row. i given this query SELECT c.intCid, c.strCompany_name, p.intProjId, p.strName, p.dteStartDate, p.dteFinalEndDate, p.strDescription, i.monTotalamount, i.intInvoiceId FROM Invoice i,Customers c,Projects p WHERE p.intProjId=i.intProjectId and p.intCid=c.intCid and p.intProjId=@intProjId but it givs the value only if the project has invoice record. can any one help me??

    S 1 Reply Last reply
    0
    • R regin

      im a begginer,i have 3 different tables [customer,invoice,projects] Customer table intcid[PK] Companyname ProjectTable intprojectId[PK], intCid[FK], strName , startdate, Invoice Table intinvoiceId[PK] intCid[FK] intProjectId[FK] monTotal i want to select these tables based on the Project name i give.. if the project doesnt have invoice also i have show the output as null in the corresponing row. i given this query SELECT c.intCid, c.strCompany_name, p.intProjId, p.strName, p.dteStartDate, p.dteFinalEndDate, p.strDescription, i.monTotalamount, i.intInvoiceId FROM Invoice i,Customers c,Projects p WHERE p.intProjId=i.intProjectId and p.intCid=c.intCid and p.intProjId=@intProjId but it givs the value only if the project has invoice record. can any one help me??

      S Offline
      S Offline
      sam
      wrote on last edited by
      #2

      use following query SELECT c.intCid, c.strCompany_name, p.intProjId, p.strName, p.dteStartDate, p.dteFinalEndDate, p.strDescription, i.monTotalamount, i.intInvoiceId FROM Invoice i LEFT OUTER JOIN Projects p ON p.intProjId=i.intProjectId and p.intProjId=@intProjId LEFT OUTER JOIN Customers c ON p.intCid=c.intCid

      R 1 Reply Last reply
      0
      • S sam

        use following query SELECT c.intCid, c.strCompany_name, p.intProjId, p.strName, p.dteStartDate, p.dteFinalEndDate, p.strDescription, i.monTotalamount, i.intInvoiceId FROM Invoice i LEFT OUTER JOIN Projects p ON p.intProjId=i.intProjectId and p.intProjId=@intProjId LEFT OUTER JOIN Customers c ON p.intCid=c.intCid

        R Offline
        R Offline
        regin
        wrote on last edited by
        #3

        thanks for the reply...but its not working.... getting all value null..

        S 1 Reply Last reply
        0
        • R regin

          thanks for the reply...but its not working.... getting all value null..

          S Offline
          S Offline
          sam
          wrote on last edited by
          #4

          i think Projects is your main table .NP run following SELECT c.intCid, c.strCompany_name, p.intProjId, p.strName, p.dteStartDate, p.dteFinalEndDate, p.strDescription, i.monTotalamount, i.intInvoiceId FROM Projects p LEFT OUTER JOIN Invoice i ON p.intProjId=i.intProjectId LEFT OUTER JOIN Customers c ON p.intCid=c.intCid WHERE p.intProjId=@intProjId

          R 1 Reply Last reply
          0
          • S sam

            i think Projects is your main table .NP run following SELECT c.intCid, c.strCompany_name, p.intProjId, p.strName, p.dteStartDate, p.dteFinalEndDate, p.strDescription, i.monTotalamount, i.intInvoiceId FROM Projects p LEFT OUTER JOIN Invoice i ON p.intProjId=i.intProjectId LEFT OUTER JOIN Customers c ON p.intCid=c.intCid WHERE p.intProjId=@intProjId

            R Offline
            R Offline
            regin
            wrote on last edited by
            #5

            thank you very much its working properly.....

            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