Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

MYSQL Query help

mindwaymindway Member Posts: 1
I have two tables.

CITY
----
City
a
b
c
d
e

CARS
----
cars | city
honda | a
civic | b
honda | c


I need a query to find cars in each city.

plz help me thaks in advance

regards
rizwan


Comments

  • IDKIDK Member Posts: 1,784
    : I have two tables.
    :
    : CITY
    : ----
    : City
    : a
    : b
    : c
    : d
    : e
    :
    : CARS
    : ----
    : cars | city
    : honda | a
    : civic | b
    : honda | c
    :
    :
    : I need a query to find cars in each city.
    :
    : plz help me thaks in advance
    :
    : regards
    : rizwan
    :
    :
    :
    I don't know sql...

    SELECT * WHERE CARS=a FROM CARS
  • zibadianzibadian Member Posts: 6,349
    : : I have two tables.
    : :
    : : CITY
    : : ----
    : : City
    : : a
    : : b
    : : c
    : : d
    : : e
    : :
    : : CARS
    : : ----
    : : cars | city
    : : honda | a
    : : civic | b
    : : honda | c
    : :
    : :
    : : I need a query to find cars in each city.
    : :
    : : plz help me thaks in advance
    : :
    : : regards
    : : rizwan
    : :
    : :
    : :
    : I don't know sql...
    :
    : SELECT * WHERE CARS=a FROM CARS
    :
    It should be:
    [code]
    SELECT * FROM CARS WHERE city = "a"; // or city = some_var
    [/code]
    But that only gives you for 1 city. To get all the cities, you'll need to make the city-comparision into a subquery. I haven't come to that part yet.
  • IDKIDK Member Posts: 1,784
    : : : I have two tables.
    : : :
    : : : CITY
    : : : ----
    : : : City
    : : : a
    : : : b
    : : : c
    : : : d
    : : : e
    : : :
    : : : CARS
    : : : ----
    : : : cars | city
    : : : honda | a
    : : : civic | b
    : : : honda | c
    : : :
    : : :
    : : : I need a query to find cars in each city.
    : : :
    : : : plz help me thaks in advance
    : : :
    : : : regards
    : : : rizwan
    : : :
    : : :
    : : :
    : : I don't know sql...
    : :
    : : SELECT * WHERE CARS=a FROM CARS
    : :
    : It should be:
    : [code]
    : SELECT * FROM CARS WHERE city = "a"; // or city = some_var
    : [/code]
    : But that only gives you for 1 city. To get all the cities, you'll need to make the city-comparision into a subquery. I haven't come to that part yet.
    :
    ok, like this?:
    SELECT * FROM CARS ORDER BY city
  • zibadianzibadian Member Posts: 6,349
    : : : : I have two tables.
    : : : :
    : : : : CITY
    : : : : ----
    : : : : City
    : : : : a
    : : : : b
    : : : : c
    : : : : d
    : : : : e
    : : : :
    : : : : CARS
    : : : : ----
    : : : : cars | city
    : : : : honda | a
    : : : : civic | b
    : : : : honda | c
    : : : :
    : : : :
    : : : : I need a query to find cars in each city.
    : : : :
    : : : : plz help me thaks in advance
    : : : :
    : : : : regards
    : : : : rizwan
    : : : :
    : : : :
    : : : :
    : : : I don't know sql...
    : : :
    : : : SELECT * WHERE CARS=a FROM CARS
    : : :
    : : It should be:
    : : [code]
    : : SELECT * FROM CARS WHERE city = "a"; // or city = some_var
    : : [/code]
    : : But that only gives you for 1 city. To get all the cities, you'll need to make the city-comparision into a subquery. I haven't come to that part yet.
    : :
    : ok, like this?:
    : SELECT * FROM CARS ORDER BY city
    :
    ORDER BY only reorders the query results based on another fields instead of the primary key. It doesn't procedure additional results.
  • IDKIDK Member Posts: 1,784
    : : ok, like this?:
    : : SELECT * FROM CARS ORDER BY city
    : :
    : ORDER BY only reorders the query results based on another fields instead of the primary key. It doesn't procedure additional results.
    :
    Yeah, but isn't that what he wants?
    I don't understand what does he wants?
    Does he want a dynamic 2D array?
Sign In or Register to comment.