That’s cool!
It’ll also probably be why you posted in the database forum and not the PHP forum.
I’ve no idea how to build logic into MySQL queries, or in fact if it can be done at all.
I’ll watch this thread with interest.
I don’t want a PHP solution. What you have posted is a workaround …not the answer to my original query.
see …I write JSP the same you write PHP. I could do the same logic in JSP side too and solve it easily ! …But that is not what I wanted…I want a solution from DB tier.
[QUOTE]and besides, in a stored procedure, you ~can~ use an IF
Thats right … But as far as I know I can not use IF - ELSE in a single select query…Can we ?
Looks like you did not understand my query. Please let me know which part you don’t understand ?
perhaps you were confused because i did not post the entire query, so here you go –
SELECT ...
FROM ...
WHERE studentid = $input
OR -1 = $input
i don’t care whether you use jsp or c-flat or whatever language, but you ~must~ feed the value of the input number (which you said was going to be either a studentid or -1) into the query somehow, and in the solution i gave you, that would be $input, which perhaps confused you because it looks like a php variable
this solution ~is~ in “the DB tier”
this solution ~is~ in the WHERE clause
please, give it a try before you say i didn’t understand your requirements
OK…well…in your example suppose I send $input = -1 …then your query becomes…
SELECT …
FROM …
WHERE studentid =-1
OR -1 = -1
are you trying to say this query will retrieve all students ?…I dont think so …because there is no -1 really in the studentid column you know… also OR part is not going to execute.
I guess this is the reason we may need to plug an IF ELSE here …and precisely this is what I’m looking for.
You didn’t try it did you? I don’t know what DB you are using, but I’ve never seen anyone that does what you are describing. What use would OR be if the second part would never be executed?