bamfon Posted January 15, 2011 Share Posted January 15, 2011 my code is this SELECT * FROM episodea, episodeb WHERE episodea.animeid = '1' OR episodeb.animeid = '1' i want the code to check the the to tables to get the data from the row's thats got animeid "1" but it keep showing data from the row thats got 2 as its animeid :s Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/ Share on other sites More sharing options...
mikosiko Posted January 15, 2011 Share Posted January 15, 2011 how both tables are related to each other?.... that select is doing a Cartesian product Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1159995 Share on other sites More sharing options...
bamfon Posted January 15, 2011 Author Share Posted January 15, 2011 well animeid has to be saved in table episodea or table episodeb set it up that wau because latter on the tables will have a few million rows, so i made 2 forms one saves info to episodea the other to episodeb, both of the tables will never have the same animeid. Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160000 Share on other sites More sharing options...
mikosiko Posted January 16, 2011 Share Posted January 16, 2011 seems that you didn't understand my answer... lets try with an example: Table A id_a Table B id_b Rows Values in Table A 1 2 Rows Values in Table B 1 2 CARTESIAN PRODUCT between Table A and Table B (result from a SELECT like yours) 1 - 1 1 - 2 2 - 1 2 - 2 applying your conditions WHERE episodea.animeid = '1' OR episodeb.animeid = '1' Final result Rows 1 - 1 and 2 - 1 more clear? Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160001 Share on other sites More sharing options...
bamfon Posted January 16, 2011 Author Share Posted January 16, 2011 Final result show all the rows with id1 and id2 Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160004 Share on other sites More sharing options...
mikosiko Posted January 16, 2011 Share Posted January 16, 2011 in addition to what was already explained check what data type is animeid .... number? Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160006 Share on other sites More sharing options...
bamfon Posted January 16, 2011 Author Share Posted January 16, 2011 data type int(11) Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160009 Share on other sites More sharing options...
mikosiko Posted January 16, 2011 Share Posted January 16, 2011 WHERE episodea.animeid = '1' OR episodeb.animeid = '1' and why then are you using strings here? Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160010 Share on other sites More sharing options...
bamfon Posted January 16, 2011 Author Share Posted January 16, 2011 what should I be using? Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160028 Share on other sites More sharing options...
mikosiko Posted January 16, 2011 Share Posted January 16, 2011 if you data type is INT(11) ideally you should be using numbers no '1'... and to fix an omission in my previous answer... ...... CARTESIAN PRODUCT between Table A and Table B (result from a SELECT like yours) 1 - 1 1 - 2 2 - 1 2 - 2 applying your conditions WHERE episodea.animeid = '1' OR episodeb.animeid = '1' Final result Rows 1 - 1 and 2 - 1 in reality the final result is Rows 1 - 1, 1 - 2 and 2 - 1 Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160032 Share on other sites More sharing options...
bamfon Posted January 16, 2011 Author Share Posted January 16, 2011 fixed it by using SELECT * FROM episodea WHERE animeid = '1' UNION ALL SELECT * FROM episodeb WHERE animeid = '1' Quote Link to comment https://forums.phpfreaks.com/topic/224565-help-before-i-break-my-laptop-d/#findComment-1160059 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.