beckjoh Posted March 27, 2009 Share Posted March 27, 2009 I am trying to figure out how to query my table to see if two columns are storaging identical values. For example: I have a mysql table like this: id column1 column2 1 3.65 3.65 2 4.1 Quote Link to comment Share on other sites More sharing options...
beckjoh Posted March 27, 2009 Author Share Posted March 27, 2009 Sorry I accidently hit return before I finished typing this post. I am trying to figure out how to query my table to see if two columns are storing identical values. For example: I have a mysql table like this: id column1 column2 1 3.65 3.65 2 4.10 4.10 3 5.23 5.23 I want to query the table to compare column1 and column2 to see is every row is equal or if any is not equal. They must either be all equal or if one row is not equal then the query would return false. Any help would be greatly appreciated. JB Quote Link to comment Share on other sites More sharing options...
deerly Posted March 27, 2009 Share Posted March 27, 2009 How about... $true_flag = true; $query = "SELECT * FROM table"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_object($result)) { if($row->column1 != $row->column2){ $true_flag = false; } } if($true_flag){ //do whatever } Quote Link to comment Share on other sites More sharing options...
beckjoh Posted March 27, 2009 Author Share Posted March 27, 2009 Perfect Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.