SharkBait Posted May 28, 2007 Share Posted May 28, 2007 I have the following tables: board_pcbs id | pcb_type | sap_pn ---------------------- 1 | Type1 | 29-23032-02 ---------------------- 2 | Type2 | 29-30230-01 ---------------------- board_tracking id | type | serial | date_entered ------------------------------------- 1 | Type1 | 1231 | 2007-01-01 00:00:01 ------------------------------------- 2 | Type1 | 2343 | 2007-01-01 00:00:31 ------------------------------------- 3 | Type2 | 2399 | 2007-01-01 00:01:02 ------------------------------------- Now I understand I could of pointed the board_tracking.pcb_type to the board_pcbs.id but this was kind of an envolving project and this is how it is now What I am trying to do is Join board_tracking to board_pcbs so that it will show the sap_pn in the results based on pcb_entries.type = board_pcbs.pcb_type This is how my query looks: SELECT T1.type, T2.sap_pn, COUNT(*) FROM board_tracking AS T1 LEFT JOIN board_pcbs AS T2 ON (T1.type = T2.pcb_type) WHERE T1.date_entered >= '2007-05-28 00:00:01' AND T1.date_entered <= '2007-05-28 23:59:59'GROUP BY T1.type It returns NULL for sap_pn and I am not sure why. I am assuming I am doing something wrong T1.type | T2.sap_pn | Count(*) --------------------------------------- Type1 | NULL | 2 --------------------------------------- Type2 | NULL | 1 --------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/53298-solved-help-with-join/ Share on other sites More sharing options...
Wildbug Posted May 28, 2007 Share Posted May 28, 2007 For the data listed, the query's dates are out of their range. mysql> SELECT T1.type, T2.sap_pn, COUNT(*) FROM board_tracking AS T1 LEFT JOIN board_pcbs AS T2 ON (T1.type = T2.pcb_type) WHERE T1.date_entered >= '2007-05-28 00:00:01' AND T1.date_entered <= '2007-05-28 23:59:59' GROUP BY T1.type; Empty set (0.00 sec) mysql> SELECT T1.type, T2.sap_pn, COUNT(*) FROM board_tracking AS T1 LEFT JOIN board_pcbs AS T2 ON (T1.type = T2.pcb_type) GROUP BY T1.type; +--------+-------------+----------+ | type | sap_pn | COUNT(*) | +--------+-------------+----------+ | Type 1 | 29-23032-02 | 2 | | Type 2 | 29-30230-01 | 1 | +--------+-------------+----------+ 2 rows in set (0.00 sec) Quote Link to comment https://forums.phpfreaks.com/topic/53298-solved-help-with-join/#findComment-263405 Share on other sites More sharing options...
SharkBait Posted May 28, 2007 Author Share Posted May 28, 2007 Woops yea, I meant to put the proper dates Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/53298-solved-help-with-join/#findComment-263418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.