Pulling related data from relational dB re: thread: Problems with a many-to-many inse

Thread Solved

Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #11
Nov 19th, 2008
This may seem like an idiot response but can you clarify what you mean by structure so I don't send you the wrong thing?

D
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #12
Nov 19th, 2008
the table schema, if you want you can send a backup if its small enough
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many

 
0
  #13
Nov 19th, 2008
Here you go:

  1. --
  2. -- Database: `fsmgroup3`
  3. --
  4.  
  5. -- --------------------------------------------------------
  6.  
  7. --
  8. -- Table structure for table `access`
  9. --
  10.  
  11. DROP TABLE IF EXISTS `access`;
  12. CREATE TABLE `access` (
  13. `access_id` INT(11) NOT NULL AUTO_INCREMENT,
  14. `access` VARCHAR(10) NOT NULL DEFAULT '',
  15. PRIMARY KEY (`access_id`)
  16. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
  17.  
  18. -- --------------------------------------------------------
  19.  
  20. --
  21. -- Table structure for table `airport`
  22. --
  23.  
  24. DROP TABLE IF EXISTS `airport`;
  25. CREATE TABLE `airport` (
  26. `airport_id` INT(11) NOT NULL AUTO_INCREMENT,
  27. `airport_name` VARCHAR(100) NOT NULL DEFAULT '',
  28. `airport_code` CHAR(3) NOT NULL DEFAULT '',
  29. PRIMARY KEY (`airport_id`)
  30. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
  31.  
  32. -- --------------------------------------------------------
  33.  
  34. --
  35. -- Table structure for table `service`
  36. --
  37.  
  38. DROP TABLE IF EXISTS `service`;
  39. CREATE TABLE `service` (
  40. `service_id` INT(11) NOT NULL AUTO_INCREMENT,
  41. `service` VARCHAR(25) NOT NULL DEFAULT '',
  42. PRIMARY KEY (`service_id`)
  43. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
  44.  
  45. -- --------------------------------------------------------
  46.  
  47. --
  48. -- Table structure for table `title`
  49. --
  50.  
  51. DROP TABLE IF EXISTS `title`;
  52. CREATE TABLE `title` (
  53. `title_id` INT(11) NOT NULL AUTO_INCREMENT,
  54. `title` VARCHAR(4) NOT NULL DEFAULT '',
  55. PRIMARY KEY (`title_id`)
  56. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
  57.  
  58. -- --------------------------------------------------------
  59.  
  60. --
  61. -- Table structure for table `userairportservices`
  62. --
  63.  
  64. DROP TABLE IF EXISTS `userairportservices`;
  65. CREATE TABLE `userairportservices` (
  66. `userairportservices_id` INT(11) NOT NULL AUTO_INCREMENT,
  67. `usr_id_users` INT(11) NOT NULL DEFAULT '0',
  68. `airport_id_airport` INT(11) NOT NULL DEFAULT '0',
  69. `service_id_service` INT(11) NOT NULL DEFAULT '0',
  70. PRIMARY KEY (`userairportservices_id`),
  71. KEY `usr_id_users` (`usr_id_users`),
  72. KEY `airport_id_airport` (`airport_id_airport`),
  73. KEY `service_id_service` (`service_id_service`)
  74. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
  75.  
  76. -- --------------------------------------------------------
  77.  
  78. --
  79. -- Table structure for table `users`
  80. --
  81.  
  82. DROP TABLE IF EXISTS `users`;
  83. CREATE TABLE `users` (
  84. `usr_id` INT(11) NOT NULL AUTO_INCREMENT,
  85. `usr_access` INT(11) NOT NULL DEFAULT '0',
  86. `usr_title` INT(11) DEFAULT NULL,
  87. `usr_fname` VARCHAR(75) NOT NULL DEFAULT '',
  88. `usr_lname` VARCHAR(75) NOT NULL DEFAULT '',
  89. `usr_add1` VARCHAR(75) NOT NULL DEFAULT '',
  90. `usr_add2` VARCHAR(75) DEFAULT NULL,
  91. `usr_add3` VARCHAR(75) DEFAULT NULL,
  92. `usr_city` VARCHAR(75) NOT NULL DEFAULT '',
  93. `usr_prov_state` CHAR(2) NOT NULL DEFAULT '',
  94. `usr_pcode` VARCHAR(10) NOT NULL DEFAULT '',
  95. `usr_cntry` VARCHAR(75) NOT NULL DEFAULT '',
  96. `usr_acode` VARCHAR(4) NOT NULL DEFAULT '',
  97. `usr_phone` VARCHAR(15) NOT NULL DEFAULT '',
  98. `usr_email` VARCHAR(75) NOT NULL DEFAULT '',
  99. `usr_pass` VARCHAR(12) NOT NULL DEFAULT '',
  100. PRIMARY KEY (`usr_id`)
  101. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #14
Nov 19th, 2008
thanks, how soon do you need it?

cool if i get back with you in the morning?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #15
Nov 19th, 2008
Of course ... whenever you can. I appreciate it.

Dave
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #16
Nov 19th, 2008
sure man, will work on it right after i get to work in the morning

...ahhhh, a fresh mind
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #17
Nov 20th, 2008
this should do the trick, the only problem is if you ever add services, you will need to change the query to reflect that

  1. SELECT usr_id_users as USR_ID, airport_id_airport AS AIRPORT_ID,
  2. a.airport_code AS AIRPORT_CODE,
  3. max(if(service_id_service=1, 1, 0)) as JET,
  4. max(if(service_id_service=2, 1, 0)) as GROUND,
  5. max(if(service_id_service=3, 1, 0)) as GLYCOL
  6. FROM userairportservices uas
  7. INNER JOIN airport a
  8. on a.airport_id = uas.airport_id_airport
  9. -- change this for different users
  10. WHERE usr_id_users = 1
  11. GROUP BY airport_id_airport;
Last edited by dickersonka; Nov 20th, 2008 at 9:58 am.
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many

 
0
  #18
Nov 20th, 2008
Thanks for this. I will not have a chance to get to it until Friday hopefully but will let you hnow how it goes. Can you explain this statement to me?

max(if(service_id_service=1, 1, 0)) as JET

I am not sure what the max statement means so a brief explanation to get me started would be appreciated.

Thanks a lot for all your time and help.

Dave
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse

 
0
  #19
Nov 20th, 2008
basically there will be rows, that will be null (its set to 0 in the the if statement), because the rows are columns, if the service_id != 1 then the row will be null

therefore, the max will pull the highest, which will be 1 if the entry is there

think of it like for columns JET GROUND and GLYCOL

1 0 0
0 1 0
0 0 1

the max, allows us to group these three rows and select "1" if the service is enabled, although its in a different row

let me know if i need to explain it a little better
Last edited by dickersonka; Nov 20th, 2008 at 9:46 pm.
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Pulling related data from relational dB re: thread: Problems with a many-to-many

 
0
  #20
Nov 21st, 2008
Hey ... just wanted to let you know that I got this working .. and now understand this quite a bit more, thanks to you. I really do appreciate your help.

Cheers

Dave
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC