本文介绍了避免重复查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,我试图让它返回没有重复的结果。我认为的问题是,当一家餐馆位于一个以上的城市和/或它在一个城市内有许多地点时。这就是我到目前为止。



桌子

tblRestaurant RestID,RestName

tblLocations LocationID,RestID

tblCities CityID,CityName

tblAreas AreaID,AreaName



MySQL代码。



I have a query and I am trying to have it return results without duplicates. The problem I think is that when a restaurant is located in more than one city and/or it has many locations within one city. This is what I have so far.

Tables
tblRestaurant RestID, RestName
tblLocations LocationID, RestID
tblCities CityID, CityName
tblAreas AreaID, AreaName

The MySQL code.

SELECT
    tblLocations.RestID
    , tblLocations.LocationID
    , tblRestaurants.RestName
    , tblCities.CityName
    , tblAreas.AreaName
FROM
     tblAreas INNER JOIN
     (
        tblCities INNER JOIN
        (
            tblRestaurants INNER JOIN
                tblLocations
                ON
                tblRestaurants.RestID = tblLocations.RestID
        )
       ON
       tblCities.CityID = tblLocations.CityID
     )
     ON
     tblAreas.AreaID = tblLocations.AreaID
GROUP BY
     tblLocations.RestID
     , tblLocations.LocationID
     , tblRestaurants.RestName
     , tblCities.CityName
     , tblAreas.AreaName
ORDER BY tblRestaurants.RestName;

推荐答案



这篇关于避免重复查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:13