SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    Moscow
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm get into a mess!

    Hello everybody! It's seems to stupidly, but i can't to understand my problem:

    Look, for example it's to exist a simple table:


    Cities |Numbers
    -----------|----------
    Moscow |1
    Paris |2
    New York|3
    Boston |8
    Tokyo |6

    I need to select only those cities, which numbers is strongly 8 and 6 (i need to get a Boston and Tokyo). It's seems to me, that it's necessary to use so query: SELECT cities FROM table WHERE numbers=8 AND numbers=6; But mysql have to return a 0 rows form me. Maybe i something not to understand, but it's query will be a fine works with the BETWEEN condition: for example WHERE numbers BETWEEN 5 AND 10; Return Boston and Tokyo. It's also fine working with the so condition: WHERE numbers != 1 AND numbers !=2 AND numbers !=3; return Boston and Tokyo.
    So, why it's don't working with my query (SELECT cities FROM table WHERE numbers=8 AND numbers=6; ) and maybe it's possible to replace this query by some alternative ?
    Thank your and please, sorry for my language - i'm a russian !

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    The reason it is not working is because your query reads SELECT the city from the TABLE that has number = 6 AND number = 8, of which, there aren't any.

    Try this: SELECT cities FROM table WHERE numbers = 8 OR numbers = 6;

  3. #3
    SitePoint Member
    Join Date
    Oct 2004
    Location
    Moscow
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everybody says me to use OR in condition, but i need a strongly fixed row of numbers. For example we have to add a Washington city with the number 6. So with OR constraction we got Boston, Tokyo and Washington. So, in this situation a Washington city is excess. But i need only Boston and Tokyo cities. Thank you !

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    But you will get Washington no matter what if you have two cities with the number 6 unless you specifically specify 'Washington' in the WHERE clause.


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
  •