Results 1 to 5 of 5

Thread: mysql query

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    32

    mysql query

    Can anybody tell me whts wrong with this query SELECT * FROM `tbl_stock` WHERE code in (select code FROM tbl_stock)
    never mind the logic!! My concern is that it shows querry error.

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: mysql query

    it looks to me like this part needs something after it, like an = 0 or = "whaterver"
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: mysql query

    The syntax is valid, the issue is likely to be the field or table names being invalid (they aren't in the reserved words list, but they may still be conflicting), or that MySQL is confused about what you are doing.

    For the latter issue, it would probably be better to use an alias in the subquery, eg:
    Code:
    (select t2.code FROM tbl_stock t2)

  4. #4
    Hyperactive Member kxcntry99's Avatar
    Join Date
    Jun 2006
    Location
    Pennsylvania
    Posts
    342

    Re: mysql query

    Does MySQL even support the "code in" function? I have never tried it.
    Microsoft Office Integration:Useful Database Links:
    Connection Strings


    Im a pogramar
    Iam a programer
    I’m a programor

    I write code!

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: mysql query

    The IN keyword is standard SQL - I would be extremely surprised if any of the popular DBMSs don't support it.

    Typically you will use IN with a list of values. In the help for SQL Server (Books Online) they show this example of IN:
    Code:
    ...
    WHERE e.Title IN ('Design Engineer', 'Tool Designer', 'Marketing Assistant')
    ..and the equivalent without IN:
    Code:
    ...
    WHERE e.Title = 'Design Engineer' 
       OR e.Title = 'Tool Designer' 
       OR e.Title = 'Marketing Assistant'

    The fact that you can use a query to get the values (instead of a fixed list like in the example), means that you can perform much more powerful queries, with far less effort (and much more speed) than writing code to do the same thing.

Posting Permissions

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



Click Here to Expand Forum to Full Width