I have a table with 3 cols, incremeting id, name, and data
What i'm trying to achieve
you enter a $name... and returns $data...
then
it takes $data and finds all $names that have the same $data.
SELECT * FROM table WHERE name ='$name' data='$data' and data!='0'
does not seem to cut it..
I'm basically trying to get all rows that have the same data as the entered $name's $data.
thanks in advance.
SELECT * FROM table WHERE name ='$name' and data='$data' and data!='0'
You were missing an and
EDIT:
select * from table where
name in
( select data from table where name = '$name' )
Try joining the table with itself, if you must do this in one query:
SELECT * FROM table t1,table t2 WHERE t1.name = '$name' AND t1.data=t2.data AND t1.name != t2.name
Alternately, use a nested query:
SELECT name FROM table WHERE data IN (SELECT data FROM table WHERE name='$name')
I recommend the nested query. It's easier to read.
What's wrong with your original query as posted is that you're missing an 'AND'. But it also won't do what you say you want it to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With