I have the following code in the my stored procedure:
SET cont_email = SELECT email from contacts WHERE id=in_id;
IF in_customer_email = cust_email then
**do something**
So, I was wondering if instead of creating a local variable and storing the result from the SELECT statement I just paste it directly in the if statement like so:
IF in_customer_email = (SELECT email from contacts WHERE id=in_id) then
**do something**
Also, I was wondering how I can use ORs in MySQL.
Can I do this?
IF in_customer_email = customer_email OR in_customer_name = customer_name THEN
I have seen the use of OR like this:
SELECT customer_id, customer_name
FROM customers
WHERE (customer_name = 'Apple' OR customer_name = 'Samsung')
but never inside of an if statement, so I wasn't sure.
And lastly, it has been ages since I could use something like if var1 = var2
, since this is usually used for assigning not to compare, so I was wondering if this correct or I have to use double equal sign like var1 == var2
.
Thanks.