select data from mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    select data from mysql

    I have a table named as tb1 and have two fields ID and CITY. One city can have more than one id. I want to write a query to select ids from tb1 in one city.
    Eg. if city1 has id1,id2,id3 then i want to dispay all three ids that is in city1.
    i'm new to mysql and please someone help me..
  • pooga17
    New Member
    • Mar 2008
    • 1

    #2
    Originally posted by ghjk
    I have a table named as tb1 and have two fields ID and CITY. One city can have more than one id. I want to write a query to select ids from tb1 in one city.
    Eg. if city1 has id1,id2,id3 then i want to dispay all three ids that is in city1.
    i'm new to mysql and please someone help me..

    select id,city from tb1
    where city in (select city from city1)

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      Originally posted by ghjk
      I have a table named as tb1 and have two fields ID and CITY. One city can have more than one id. I want to write a query to select ids from tb1 in one city.
      Eg. if city1 has id1,id2,id3 then i want to dispay all three ids that is in city1.
      i'm new to mysql and please someone help me..
      Try this:

      [code=mysql]

      SELECT id from tb1 WHERE city = 'city1';

      [/code]

      Comment

      Working...