I am trying to run this query SELECT * FROM dftree WHERE (SELECT lineage FROM dftree WHERE id = @id) LIKE lineage + '%' But I get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '+ '%'' at line 1 Can someone tell me what I am doing wrong?
dunno man - but it might be easier to troubleshoot if you ran it in 2 seperate queries. the syntax is different than what i'm used to so i can't comment on that - other than i generally see ampersands rather than plus signs in sql but i work in visual basic so i doubt that's the issue... then again it does seem to indicate that that's where the problem is.
I agree one query to $var = mysql_query('SELECT lineage FROM dftree WHERE id = @id') and then: SELECT * FROM dftree WHERE $var LIKE lineage + '%' ((not perfect syntax, play with it..))
I find that if I have trouble making queries work, it would be useful to actually write down what I want in English first. If I still can't get it to work, then perhaps the database needs redesigning. SELECT * FROM dftree WHERE [COLOR="Red"]dftree.lineage IN[/COLOR] (subquery) [COLOR="Red"]AND something[/COLOR] LIKE lineage + '%' Code (markup): if you are trying to find those records where the last character of the lineage field is a '%', then use RIGHT(lineage,1)='%'