How to use NOT EQUAL symbol in php


#1

Actually i am doing

SELECT * FROM position_master
inner join targets on position_master.position_id != targets.position_id

but it shows null value only…?

what i did wrong…?


#2

You cant do a join on columns that do not equal each other. Remove the exclamation point.

SELECT * FROM position_master
inner join targets on position_master.position_id = targets.position_id;

Since the ID columns are the same name you can also use USING

SELECT * FROM position_master
inner join targets USING (position_id);


#3

This is NOT PHP ! It is MySQL…

The exclamation character is used in PHP for NOT, but, in MySQL (queries) you have to write it in a different way. You would either use <> which is not-equal in a query or use not-in and a second select clause.

So, SELECT * FROM position_master
inner join targets on position_master.position_id <> targets.position_id


#4

Joining columns that do not equal the columns of a ON clause??? Please provide anything that supports such a thing.


#5

Sorry, Kev, I’m brain-dead today! You would need to do something like this, I think!
( Assuming he wants all of the master items not in the targets table… )

SELECT * FROM position_master 
  WHERE position_id NOT IN (SELECT position_id FROM targets)

But, you are the master coder for this type of thing, not me! Always bow to you on these!
Sorry, I read the entire post this time! Ha!


#6

LOL! I knew it was a simple brain fade.:grinning:


#7

thank you