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

SQL server join issues

Options
  • 29-07-2006 9:19am
    #1
    Registered Users Posts: 872 ✭✭✭


    Hi,

    I am trying to make a query using 3 tables.

    tables are feature_set,image_set and image_set_image

    the first part is to display all the feature_sets

    then i display image_sets if there are any related to feature_sets

    then i display image_set_images only if there are any related to image_Sets.

    select fs.feature_set_id,fs.name,fs.property_id,i.image_set_id,i.feature_set_id,isi.image_set_image_id,isi.image_url from dbo.feature_set fs
    inner join image_set i on fs.feature_set_id = i.feature_set_id
    left join image_set_image isi on i.image_set_id = isi.image_set_id

    where property_id = @property_id


    i know its way wrong and i think its to do with the joins.

    Basically i need all image_sets to appear even if there are no image_set_images.

    I hope i have made myself clear.

    Thanks


Comments

  • Registered Users Posts: 2,931 ✭✭✭Ginger


    Use Outerjoins instead of Inner Joins

    Inner Joins require a corresponding row based on the join criteria. ie join where id = id. So if they dont have an id it wont appear. Outer join will decide then .. Use left or right depending on which side of the expression you want the rows to appear.

    If you are using SQL Server, they you can use the view designer to help you with the queries


Advertisement