Forum Moderators: coopster

Message Too Old, No Replies

Conditionality in a MySQL query

         

sjariri

12:52 pm on May 17, 2005 (gmt 0)

10+ Year Member



I have two tables: TableA (FirstName, Flag) and TableB (FirstName). What I am trying to do is to write a single MySQL query that has the result of such logic:

IF (TableA.Flag='yes')

Query: Select * from TableA where TableA.FirstName=TableB.FirstName

ELSE

Query: Select * from TableA

I want to have this logic as a single MySQL query. (Otherwise a PHP/MySQL solution could bring all values and build the query dynamically). Any hint on how I can do such thing?

sjariri

2:46 pm on May 17, 2005 (gmt 0)

10+ Year Member



Sorry. It was a whole confusing situation while trying to write a very long query. Every conditionality and stuff were (and should usually be) sorted out in the query "WHERE" part.

Sarah Atkinson

3:32 pm on May 17, 2005 (gmt 0)

10+ Year Member



I don't understand the
IF (TableA.Flag='yes')

for a table you basicly have an x and y. TableA.Flag is your collum if what row do you want to == yes? do you want the whole colum to == yes or just one entry? you will have to do an additional querry to get the value too.

killroy

11:45 pm on May 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps use the MySQL conditional IF?