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 can I get match with any one of Table2

How can I get match with any one of Table2

Scheduled Pinned Locked Moved Database
questionregexhelp
2 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.
  • A Offline
    A Offline
    azusakt
    wrote on last edited by
    #1

    Dear All, I have a question about joining 2 table. e.g. table1 contains user---inv---amount---data2 a --- 001--- 1000 --- dfsdf st --- 001--- 1200 --- sdfs b --- 002--- 1300 --- sdf c --- 004--- 1400 --- sdf e.g. table2 contains cid--- data--- FromCountry 001--- acd--- USA 001--- efg --- USA 001--- okk --- USA 002--- cce --- CHI 003--- eer --- UK 003--- err --- UK 004--- edr --- VOC I would like to construct a table base on table1, and include the field "FromCountry" from table2. I use select table1.user, table1.inv, table2.FromCountry From table1, table2, Where table1.inv = table2.cid when joining 2 table, I found there are duplicated records generated... How can I just get the "FromCountry" from any one of "cid" record in table2? The perfer result on new table is: user --- inv --- FromCountry a --- 001 --- USA st --- 001 --- USA b --- 002 --- CHI c --- 004 --- VOC PLEASE HELP

    B 1 Reply Last reply
    0
    • A azusakt

      Dear All, I have a question about joining 2 table. e.g. table1 contains user---inv---amount---data2 a --- 001--- 1000 --- dfsdf st --- 001--- 1200 --- sdfs b --- 002--- 1300 --- sdf c --- 004--- 1400 --- sdf e.g. table2 contains cid--- data--- FromCountry 001--- acd--- USA 001--- efg --- USA 001--- okk --- USA 002--- cce --- CHI 003--- eer --- UK 003--- err --- UK 004--- edr --- VOC I would like to construct a table base on table1, and include the field "FromCountry" from table2. I use select table1.user, table1.inv, table2.FromCountry From table1, table2, Where table1.inv = table2.cid when joining 2 table, I found there are duplicated records generated... How can I just get the "FromCountry" from any one of "cid" record in table2? The perfer result on new table is: user --- inv --- FromCountry a --- 001 --- USA st --- 001 --- USA b --- 002 --- CHI c --- 004 --- VOC PLEASE HELP

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      here it is:

      SELECT DISTINCT table1.[USER],table1.inv,table2.fromcountry
      FROM table1,table2
      WHERE table1.inv=table2.cid 
      ORDER BY table1.inv
      

      I Love T-SQL "Don't torture yourself,let the life to do it for you."

      modified on Wednesday, August 13, 2008 8:37 AM

      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