![]() |
selecting data from 2 tables - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: selecting data from 2 tables (/showthread.php?tid=40702) |
selecting data from 2 tables - El Forum - 04-18-2011 [eluser]Bigil Michael[/eluser] when i change year and constituence result print like this string(167) "SELECT * FROM (`candidate_details`) WHERE `constituency_id` = '1' AND `elect_year` = '2011' AND `candidate_votes` = (SELECT MAX(candidate_votes)FROM candidate_details)" array(0) { } selecting data from 2 tables - El Forum - 04-18-2011 [eluser]Bigil Michael[/eluser] candidate votes integer selecting data from 2 tables - El Forum - 04-18-2011 [eluser]toopay[/eluser] Unbelievable. Run this query directly in mysql daemon or phpmyadmin Code: SELECT * FROM candidate_details WHERE constituency_id = '1' AND elect_year = '2011' AND candidate_votes = (SELECT MAX(candidate_votes) FROM candidate_details selecting data from 2 tables - El Forum - 04-18-2011 [eluser]Bigil Michael[/eluser] upto this it is running SELECT * FROM candidate_details WHERE constituency_id = '1' AND elect_year = '2011' when i use fullcode SELECT * FROM candidate_details WHERE constituency_id = '1' AND elect_year = '2011' AND candidate_votes = (SELECT MAX(candidate_votes) FROM candidate_details it shows error like this #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 selecting data from 2 tables - El Forum - 04-18-2011 [eluser]toopay[/eluser] Code: SELECT * FROM candidate_details WHERE constituency_id = '1' AND elect_year = '2011' AND candidate_votes = (SELECT MAX(candidate_votes) FROM candidate_details) selecting data from 2 tables - El Forum - 04-18-2011 [eluser]Bigil Michael[/eluser] now error gone but it prints 0 rows selecting data from 2 tables - El Forum - 04-18-2011 [eluser]toopay[/eluser] Pfff. Its sounds unbelievable. Ok, try it step by step. Code: SELECT * FROM candidate_details WHERE candidate_votes = (SELECT MAX(candidate_votes) FROM candidate_details) selecting data from 2 tables - El Forum - 04-18-2011 [eluser]Bigil Michael[/eluser] it prints result but when i use this SELECT * FROM candidate_details WHERE constituency_id = '1' AND elect_year = '2011' AND candidate_votes = (SELECT MAX(candidate_votes) FROM candidate_details) prints 0 result selecting data from 2 tables - El Forum - 04-18-2011 [eluser]toopay[/eluser] Is there ANY RECORD which match with above 'where' rules? selecting data from 2 tables - El Forum - 04-18-2011 [eluser]Bigil Michael[/eluser] yes 3 records are there i will send the table Quote:id constituency_id candidate_name candidate_votes elect_year |