locked
SQL query RRS feed

  • Question

  •  

    I am new here, so not sure if here is the right place to post this kind of qiz, anyway, have a try.

     

    I've created two tables:

     

    type_id ------ type_name
    1 ----------------house
    2 ----------------apartment
    3 ----------------shop

    property_id ------- property_price ------- type
    1 ----------------------10,000--------------------- 2
    2 ----------------------50,000--------------------- 3
    3---------------------- 20,000 ---------------------1
    4 ----------------------15,000 ---------------------1

    and then I tried to write a php page to get users' input keyword, which is one of house, apartment or shop(or part thereof) , to get the relevent property records, could anyone please give me some ideas of how to write the correct SQL query of doing this? BTW, the type is the foreign key of table Property. Thx in advance.
    Saturday, September 27, 2008 3:15 PM

Answers

  •  

    Here you go

    Code Snippet

     

    SELECT a.property_id, a.property_price, b.type_name

    FROM property_table A

    INNER JOIN

    type_table B

    ON a.type=b.type_id

     

     

    Saturday, September 27, 2008 3:24 PM

All replies

  •  

    Here you go

    Code Snippet

     

    SELECT a.property_id, a.property_price, b.type_name

    FROM property_table A

    INNER JOIN

    type_table B

    ON a.type=b.type_id

     

     

    Saturday, September 27, 2008 3:24 PM
  •  

    spot on!

     

    Thx for the reply.

    Saturday, September 27, 2008 4:00 PM