Jump to content


set_relation with table prefix

set_relation

  • Please log in to reply
5 replies to this topic

#1 kanted

kanted

    Member

  • Members
  • PipPip
  • 19 posts

Posted 15 November 2015 - 11:56 AM

Table1 has  id, firstname, lastname

Table2 has A|id, address,city. A|id is the primary key. how do i set relationship. since id column  has a prefix of "A|" 

 



#2 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts
  • LocationUkraine

Posted 15 November 2015 - 12:51 PM

http://www.grocerycr...set_primary_key



#3 kanted

kanted

    Member

  • Members
  • PipPip
  • 19 posts

Posted 15 November 2015 - 01:38 PM

Great Thanks Paul. But except  A|id no other column is primary key & how would i relate it with other table. only difference in table is it has a prefix 

 

table1: primary_key , vs a table2 prefix_primary_key no other column has primary key which can be related.

 

example 

 

employee
id name

1 steve
2 rob
3 bell

position
position_id  e_id       position

a                 e_1        manager
b                 e_2        seller
c                 e_3        director

 

result

name position

steve manager
rob seller
bell director



#4 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts
  • LocationUkraine

Posted 16 November 2015 - 01:12 AM

I dont understand actualy what u need in this question :(

u mean that value in table 'position' column e_id have format like e_1, e_2, e_3 or what?

if so then u should change it cause this is horribly wrong!

 

why u dont do like this one ???

employee table
id name

1 steve
2 rob
3 bell

 

position table
id  employe
r_id       position
1        1                   manager
2        2                   seller
3         3                 director



#5 kanted

kanted

    Member

  • Members
  • PipPip
  • 19 posts

Posted 16 November 2015 - 08:05 AM

Thanks for your reply. I know that it in the regular table format as you suggested it works

 

 if we remove the prefix then it will not be the primary key. see the below table i have added more sample data. can we use concatenate option during table relation ?

 

position
position_id  e_id       position

a                 e_1        manager
b                 e_2        seller
c                 e_3        director

e                 x_1        zonemanager

f                  x_2        zoneseller



#6 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts
  • LocationUkraine

Posted 16 November 2015 - 11:52 AM

I told u,  change u database schema. U have ID in one table 1, 2, 3 and in another e_1, x_2, ???_3, ???_4.  So how u want to join that fields?







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users