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: Table, where "partnerships" are stored

SQL: Table, where "partnerships" are stored

Scheduled Pinned Locked Moved Database
databasequestionsaleshelptutorial
2 Posts 2 Posters 1 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.
  • S Offline
    S Offline
    softwarejaeger
    wrote on last edited by
    #1

    Hello, i have a little problem. I have a table "customers" and a table "partnerships". In the customer database i have stored a few customer with a ID as primary key. In my partnership database i have two columns (partner1, partner2) where i want to store partnerships between them. So now the problem, it should be unnessecary if partner1=1 and partner2=2 or partner1=2 and partner2=1. And one partnership shouldn't be stored two times. So how can i realize this? In my selects it is easy, i easily have: select * from partnerships where (partner1='1' and partner2='2') or (partner1='2' and partner2='1') But how to make the right constraints, that this isn't saved to times, so i don't want to have something like this:

    partner1 partner2
    1 2
    2 1

    Maybe someone has a solution for me?

    M 1 Reply Last reply
    0
    • S softwarejaeger

      Hello, i have a little problem. I have a table "customers" and a table "partnerships". In the customer database i have stored a few customer with a ID as primary key. In my partnership database i have two columns (partner1, partner2) where i want to store partnerships between them. So now the problem, it should be unnessecary if partner1=1 and partner2=2 or partner1=2 and partner2=1. And one partnership shouldn't be stored two times. So how can i realize this? In my selects it is easy, i easily have: select * from partnerships where (partner1='1' and partner2='2') or (partner1='2' and partner2='1') But how to make the right constraints, that this isn't saved to times, so i don't want to have something like this:

      partner1 partner2
      1 2
      2 1

      Maybe someone has a solution for me?

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

      I cant see a simple way to do this using relationships, you could set up a complex structure that concatenates the IDs in order of size and faff about with that but it would be ugly as sin. I'd just have a proc that checked for existence before inserting. OR make it a convention that the highest is always Parent 1, this does not help with constraints though it would simplify your 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