If query - 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: If query (/showthread.php?tid=58402) |
If query - El Forum - 06-09-2013 [eluser]Cosai[/eluser] I want a query like this: IF sometable.id=-1THEN select "" as name1 ELSE select othertable.name as name1 END From sometable,othertable LEFT JOIN sometable.id=othertable.sid There are some fields on sometable that doesn't (shouldn't) match on othertable. If the field matches then I need to get name on other table else the name should appear 0 (Don't ask me why is it like that. Someone has done this sh.tty database design) also is it possible to start a query then before taking result of that starting another query? Thank you for your help. If query - El Forum - 06-10-2013 [eluser]bgreene[/eluser] select id,job,hobby,IF(id="-1","",name1) AS "aname" FROM etc >>is it possible to start a query then before taking result of that starting another query? you could do that in a stored procedure using a cursor to scan the results of one query and based on each row, call the second query If query - El Forum - 06-10-2013 [eluser]Cosai[/eluser] Thank you very much Any idea about how to do that in CodeIgniter? If query - El Forum - 06-10-2013 [eluser]bgreene[/eluser] stored proc is in the database, same way as a table is. create it using heidimysql (freeware) or similar. then all u need in ci is a single qry like "select * from myprocedurename(filtervalue or whatever)" but u need to read up on stored procs |