www.webdeveloper.com
Results 1 to 7 of 7

Thread: Join question

  1. #1
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544

    Join question

    Hi

    I have a search form with six conditions to be searched and the query is always generated appending ANDīs after a WHERE 1=1 clause

    My problem is that selecting one relator and typing the search string "Drunk Driving" brings me all the texts whose content is Drunk Driving with diferent relators

    eg.:
    text cod_relator
    +------------+-----------+
    Drunk Driving 12
    +------------+-----------+
    Drunk Driving 13
    +------------+-----------+
    Drunk Driving 21

    How can i bring just the texts with the relator code i am querying and the search string i type? I am querying just one table.

    eg.:
    text cod_relator
    +------------+-----------+
    Drunk Driving 12
    +------------+-----------+
    Drunk Driving 12
    +------------+-----------+
    Drunk Driving 12

    Thankīs in advance
    Code:
    SELECT
     * 
    FROM
     juris 
    WHERE 1=1 
    AND int_cod_relator =31    
    AND txt_ementa LIKE UPPER('%Drunk Driving%') OR txt_indexacao LIKE UPPER('%Drunk Driving%')               
    AND int_public = 1
    Last edited by amrigo; 02-16-2006 at 12:46 PM.

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    parenthesize the logic you expect to occur.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544
    Hi
    I try :
    Code:
    SELECT * 
    FROM juris 
    WHERE 1=1 
    (
    AND int_cod_relator =31    
    AND txt_ementa LIKE UPPER('%Drunk Driving%') OR txt_indexacao LIKE UPPER('%Drunk Driving%')               
    AND int_public = 1
    )
    but return a #1064 error (near line (
    AND int_cod_relator =31
    AND txt_ementa LIKE UPPER('%Drunk Driving%') OR txt_indexacao LIKE UPPER('%Drunk Driving%')
    AND int_public = 1
    )

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    What do you want to and together and what do you want to or together?

    mysql's reading it like this:
    Code:
    SELECT * 
    FROM juris 
    WHERE (1=1 
    AND int_cod_relator =31    
    AND txt_ementa LIKE UPPER('%Drunk Driving%')) OR (txt_indexacao LIKE UPPER('%Drunk Driving%')
    AND int_public = 1)
    Last edited by chazzy; 02-16-2006 at 02:50 PM.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  5. #5
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544
    yes i need these conditions:
    int_cod_relator =31
    txt_ementa LIKE UPPER('%Drunk Driving%')) OR (txt_indexacao LIKE UPPER('%Drunk Driving%')
    int_public = 1

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    then put proper parenthesis around the login how you expect it to work. and you also need to include all of your logic (including 1=1 and i have no clue why you are including that.)
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  7. #7
    Join Date
    Feb 2004
    Location
    Brasil porto Aelgre
    Posts
    544
    Hi
    this workīs
    thankīs a lot
    best regards
    Code:
    SELECT * 
    FROM juris 
    WHERE 1=1 
    AND int_cod_relator =31    
    AND (txt_ementa LIKE '%Drunk Driving%' OR txt_indexacao LIKE '%Drunk Driving%' )
    AND int_public = 1

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles