| | |
Pulling related data from relational dB re: thread: Problems with a many-to-many inse
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse
0
#11 Nov 19th, 2008
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
Re: Pulling related data from relational dB re: thread: Problems with a many-to-many
0
#13 Nov 19th, 2008
Here you go:
MySQL Syntax (Toggle Plain Text)
-- -- Database: `fsmgroup3` -- -- -------------------------------------------------------- -- -- Table structure for table `access` -- DROP TABLE IF EXISTS `access`; CREATE TABLE `access` ( `access_id` INT(11) NOT NULL AUTO_INCREMENT, `access` VARCHAR(10) NOT NULL DEFAULT '', PRIMARY KEY (`access_id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -------------------------------------------------------- -- -- Table structure for table `airport` -- DROP TABLE IF EXISTS `airport`; CREATE TABLE `airport` ( `airport_id` INT(11) NOT NULL AUTO_INCREMENT, `airport_name` VARCHAR(100) NOT NULL DEFAULT '', `airport_code` CHAR(3) NOT NULL DEFAULT '', PRIMARY KEY (`airport_id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ; -- -------------------------------------------------------- -- -- Table structure for table `service` -- DROP TABLE IF EXISTS `service`; CREATE TABLE `service` ( `service_id` INT(11) NOT NULL AUTO_INCREMENT, `service` VARCHAR(25) NOT NULL DEFAULT '', PRIMARY KEY (`service_id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -------------------------------------------------------- -- -- Table structure for table `title` -- DROP TABLE IF EXISTS `title`; CREATE TABLE `title` ( `title_id` INT(11) NOT NULL AUTO_INCREMENT, `title` VARCHAR(4) NOT NULL DEFAULT '', PRIMARY KEY (`title_id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -------------------------------------------------------- -- -- Table structure for table `userairportservices` -- DROP TABLE IF EXISTS `userairportservices`; CREATE TABLE `userairportservices` ( `userairportservices_id` INT(11) NOT NULL AUTO_INCREMENT, `usr_id_users` INT(11) NOT NULL DEFAULT '0', `airport_id_airport` INT(11) NOT NULL DEFAULT '0', `service_id_service` INT(11) NOT NULL DEFAULT '0', PRIMARY KEY (`userairportservices_id`), KEY `usr_id_users` (`usr_id_users`), KEY `airport_id_airport` (`airport_id_airport`), KEY `service_id_service` (`service_id_service`) ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ; -- -------------------------------------------------------- -- -- Table structure for table `users` -- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `usr_id` INT(11) NOT NULL AUTO_INCREMENT, `usr_access` INT(11) NOT NULL DEFAULT '0', `usr_title` INT(11) DEFAULT NULL, `usr_fname` VARCHAR(75) NOT NULL DEFAULT '', `usr_lname` VARCHAR(75) NOT NULL DEFAULT '', `usr_add1` VARCHAR(75) NOT NULL DEFAULT '', `usr_add2` VARCHAR(75) DEFAULT NULL, `usr_add3` VARCHAR(75) DEFAULT NULL, `usr_city` VARCHAR(75) NOT NULL DEFAULT '', `usr_prov_state` CHAR(2) NOT NULL DEFAULT '', `usr_pcode` VARCHAR(10) NOT NULL DEFAULT '', `usr_cntry` VARCHAR(75) NOT NULL DEFAULT '', `usr_acode` VARCHAR(4) NOT NULL DEFAULT '', `usr_phone` VARCHAR(15) NOT NULL DEFAULT '', `usr_email` VARCHAR(75) NOT NULL DEFAULT '', `usr_pass` VARCHAR(12) NOT NULL DEFAULT '', PRIMARY KEY (`usr_id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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?
cool if i get back with you in the morning?
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
Re: Pulling related data from relational dB re: thread: Problems with a many-to-many inse
0
#15 Nov 19th, 2008
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
...ahhhh, a fresh mind
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
MySQL Syntax (Toggle Plain Text)
SELECT usr_id_users as USR_ID, airport_id_airport AS AIRPORT_ID, a.airport_code AS AIRPORT_CODE, max(if(service_id_service=1, 1, 0)) as JET, max(if(service_id_service=2, 1, 0)) as GROUND, max(if(service_id_service=3, 1, 0)) as GLYCOL FROM userairportservices uas INNER JOIN airport a on a.airport_id = uas.airport_id_airport -- change this for different users WHERE usr_id_users = 1 GROUP BY airport_id_airport;
Last edited by dickersonka; Nov 20th, 2008 at 9:58 am.
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
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
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
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
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
www.houseshark.net
•
•
Join Date: Nov 2008
Posts: 73
Reputation:
Solved Threads: 1
Re: Pulling related data from relational dB re: thread: Problems with a many-to-many
0
#20 Nov 21st, 2008
![]() |
Other Threads in the MySQL Forum
- Previous Thread: Which is better? Tons of separate tables with a little data or one big table?
- Next Thread: update in steps? is it possible ?
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api aws bizspark breathalyzer changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization






