Welcome Guest, Not a member yet? Register   Sign In
If query
#1

[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.
#2

[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
#3

[eluser]Cosai[/eluser]
Thank you very muchWink Any idea about how to do that in CodeIgniter?

#4

[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




Theme © iAndrew 2016 - Forum software by © MyBB