Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

quick mysql question

  • 01-04-2008 01:58PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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
Advertisement