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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sql query question

Sql query question

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

    i have a table "Activity" contains two column "personid1" "personid2". i have to select those two column with the personname from person table. how should i write the query?

    I am Entry level person

    K U J 3 Replies Last reply
    0
    • M maxiachun

      i have a table "Activity" contains two column "personid1" "personid2". i have to select those two column with the personname from person table. how should i write the query?

      I am Entry level person

      K Offline
      K Offline
      Krish KP
      wrote on last edited by
      #2

      can you please provide structure of both tables with sampledata

      Regards KP

      1 Reply Last reply
      0
      • M maxiachun

        i have a table "Activity" contains two column "personid1" "personid2". i have to select those two column with the personname from person table. how should i write the query?

        I am Entry level person

        U Offline
        U Offline
        Urs Enzler
        wrote on last edited by
        #3

        something like that: select a.personid1, a.personid2, p1.name, p2.name from Activity a join person p1 on a.personid1 = p1.id join person p2 on a.personid2 = p2.id (didn't test it though) Furthermore, I suggest reading a book about SQL ;)

        -^-^-^-^-^- no risk no funk ................... please vote ------>

        1 Reply Last reply
        0
        • M maxiachun

          i have a table "Activity" contains two column "personid1" "personid2". i have to select those two column with the personname from person table. how should i write the query?

          I am Entry level person

          J Offline
          J Offline
          John ph
          wrote on last edited by
          #4

          Activity Table: tblActivity PersonId1 PersonId2 Person Table : tblPerson PersonId PersonName Sql Stmt : SELECT A.PersonId1, (Select PersonName from tblPerson P where P.PersonId = A.PersonId1)AS Person_Name1, A.PersonId2, (Select PersonName from tblPerson P where P.PersonId = A.PersonId2)AS Person_Name2 FROM tblActivity A Regards John

          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