I have two tables, each with a "category" field. What I want to do is query these two tables and return a list of all categories that are NOT matches.
SELECT * from categories, features where categories.category != features.category
That's sort of what I thought I needed, but boy is that ever wrong. I tried a left join but it also seemed to return ALL results, not excluding the ones that match. I think I'm making this more complicated than it needs to be in my head now.
Query: NOT matches.
Moderator: General Moderators
first off, ur query is wrong if i'm reading it correctly. you are telling the query to look at those field names as the actual table names.
what you should do is :
now, as far as the "where" clause in the query, i'm kinda lost myself.
you might be able to do something like this instead of trying to do it in the query :
hope that helps. i'm sure there is a better way, but i'm not that sure about how to do it within the actual query itself.
what you should do is :
Code: Select all
$sql = "Select categories, features from <table_name> where ...";you might be able to do something like this instead of trying to do it in the query :
Code: Select all
<?php
$sql = "Select categories, features from <table_name>";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
if (!$result)
{
echo 'no rows found!';
}
if ($result['categories'] != $result['features'])
{
// do something
}
?>Just wanted to mention that SQL's != can be written as <>.
How about the following?
Edit: Miswrote the post.
How about the following?
Code: Select all
select foo from bar where muu <> 'cow'
Last edited by JAM on Thu Nov 13, 2003 11:22 am, edited 1 time in total.
In MySQL you can use `!=`.JAM wrote:Just wanted to mention that SQL's != is written as <>.Code: Select all
select foo from bar where muu <> 'cow'