MySql Help

Discussion in 'MySQL' started by honcivex, May 4, 2006.

  1. #1
    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?
     
    honcivex, May 4, 2006 IP
  2. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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.
     
    vectorgraphx, May 5, 2006 IP
  3. donteatchicken

    donteatchicken Well-Known Member

    Messages:
    432
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    118
    #3
    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..))
     
    donteatchicken, May 5, 2006 IP
  4. rosytoes

    rosytoes Peon

    Messages:
    230
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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)='%'
     
    rosytoes, May 5, 2006 IP