SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Select Problem

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select Problem

    Hi All

    I am not too sure why I can't get this to work, I'm sure it is an easy fix but just can't get it.

    My SQL is:

    SELECT * FROM webuseraccounts WHERE type='t' OR type='ft' AND siteid='$accountname' AND active='y' AND companyname LIKE '$letter%' ORDER BY companyname asc

    If I remove the OR part it works but does not pull in all the information I need. With the OR statement in it is pulling in 4 entries that it shouldn't be.

    Any suggestions on what might be wrong with this code would be great.

    Thanks

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding brackets around your OR clause, like this:

    Code sql:
     SELECT *
       FROM webuseraccounts
      WHERE (TYPE = 't' 
         OR TYPE = 'ft')
        AND siteid = '$accountname'
        AND active = 'y'
        AND companyname LIKE '$letter%'
      ORDER
         BY companyname ASC

    P.S. you should try and avoid using SELECT * in your queries


Bookmarks

Posting Permissions

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