MySQL best approach for db normalising, relationships and foreign keys -


there username/password verification step first database has following structure

^ primary key  * uses foreign key   1.studentdetails table ===========================================================================    id^| username   | password | email       | address * | website |comments ====+============+==========+=============+===========+=========+==========  1   | xxxxxxxxxx | xxxxxxx  | xx@xxx.xxx  | 1         | http:// | text  2.submissions table =========================================================================================== id^|username*|submitdate|selectedcourse*|price*|promotion*|submitcomments|submitstatus* ===+=========+==========+===============+======+==========+==============+================= 1  |xxxxxxxxx|2013-7-12 |  int          | int  |  int     | text         | int   3.submitcomplete table ================================================== id^| username * | selectiondate | submitstatus *   ====+============+===============+================ 1   | xxxxxxxxxx |  2013-08-01   | int 

now i'm having issue entering address, when try enter student details won't accept until there address field, how best tackle that? when left join selecting fields studentdetails , fields addresses, addresses don't show.

im mysql noob, i'd guidance see if normalising , structure has been done correctly, or done better, here fiddle couldn't work properly, kept getting errors on lines added foreign keys, though building of schema worked on machine.

the fiddle console says error on line 2 looks me it's on line 76. if there's unclear on, pls let me know. thanks

ok let me explain how be. made example 2 tables can see below.

simple model

then can create query.

mysql> show tables; +----------------+ | tables_in_test | +----------------+ | addresses      | | students       | +----------------+ 2 rows in set (0.00 sec)  mysql> select * students; +----+----------+-----------+ | id | name     | last_name | +----+----------+-----------+ |  1 | jhon     | smith     | |  2 | anderson | neo       | |  3 | trinity  | jackson   | +----+----------+-----------+ 3 rows in set (0.00 sec)  mysql> select * addresses; +----+-----------------+---------+ | id | address         | student | +----+-----------------+---------+ |  1 | av 1 2nd street |       1 | |  2 | av 3 4 street   |       2 | |  3 | st 23 7 av      |       3 | +----+-----------------+---------+ 3 rows in set (0.00 sec)  mysql> select s.name,s.last_name,a.address students s join addresses on a.student=s.id; +----------+-----------+-----------------+ | name     | last_name | address         | +----------+-----------+-----------------+ | jhon     | smith     | av 1 2nd street | | anderson | neo       | av 3 4 street   | | trinity  | jackson   | st 23 7 av      | +----------+-----------+-----------------+ 3 rows in set (0.00 sec) 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -