Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

quick mysql question

Options
  • 01-04-2008 2:58pm
    #1
    Registered Users Posts: 648 ✭✭✭


    hi

    i have a property listing site im working on- i want to get the city details ffrom the city table (it_city) but i only want to show the ones that have entries in the property table (it_prop)

    how do i go about this?

    SELECT c.* FROM it_city AS c RIGHT JOIN .....


    Thanks


Comments

  • Registered Users Posts: 568 ✭✭✭phil


    i have a property listing site im working on- i want to get the city details ffrom the city table (it_city) but i only want to show the ones that have entries in the property table (it_prop)

    RIGHT JOIN matches up the two tables even if there are no matches, so that's not what you want (Bear in mind that LEFT JOIN is pretty much the same thing).

    What you're probably looking for is an INNER JOIN.
    SELECT [...] FROM it_city INNER JOIN it_prop ON it_city.id=it_prop.id WHERE [...]
    

    That's an example where the `id` field is common to both. Rename appropiately.

    Phil.


Advertisement