joined tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am no database guru and I am also new to php/mysql

I want to be able to store data where one of the fields could have multiple
values which are stored in another table

eg. the first table is called family with a field called name which contains
family names
the second table is called members with a fiedl also called name which
contains first names
the third table is an intermediate table that only contains ids of the other
tables.
(the data is below)

By using inner joins I can get a list of all the people in the database (or
other variants eg. all the people with first names of Mary)

My first question is - is this the best way to do stuff like this?
My second question is - how do I insert new data? eg to insert Mary Stevens
(the first name Mary already exists)

I hope this all makes some sense

Thanks

Neil



table - family
      id  name
      1 jones
      2 smith
      3 mcdonald
      4 talbot
      5 jackson


table - members
      id  name
      1 john
      2 mary
      3 ted
      4 sally
      5 bob
      6 jane


table - fammem
      famid  memid
      1 1
      1 3
      2 4
      5 4
      3 6
      4 1


SELECT * FROM family inner join fammem on family.id = fammem.famid inner
join members on fammem.memid  = members.id
      id  name  famid  memid  id  name
      1 jones 1 1 1 john
      1 jones 1 3 3 ted
      2 smith 2 4 4 sally
      3 mcdonald 3 6 6 jane
      4 talbot 4 1 1 john
      5 jackson 5 4 4 sally

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux