开发者

getting double results from join query

开发者 https://www.devze.com 2023-03-13 01:14 出处:网络
I am trying to query multiple tables with one query, but I am having troubles with the query. When I execute it, I get double values. The result appears twice in the list. Could someone please help me

I am trying to query multiple tables with one query, but I am having troubles with the query. When I execute it, I get double values. The result appears twice in the list. Could someone please help me and tell me what I am doing wrong

The query:

开发者_如何学PythonSELECT distinct *
FROM asset, inuse, location, user_asset
WHERE asset.aid = 95
  and asset.aid = location.asset_location_id
  and asset.aid = asset_usage_id
  and asset_id  = asset.aid
ORDER BY name ASC

The tables location,user_asset have 1 - N relationship with asset and inuse has 1-1 relationship. I assumed that DISTINCT would get rid of the problem of multiple copies. asset.aid is unique value, but is used multible times in other tables.

I get all the values on the screen, but for some reason they are shown twice.

Thank you!


That means that either:

  • you don't have only one-to-one relationships between asset and the other tables
  • or asset.aid is not a unique field, and you have several entries matching asset.aid = 95

As advised by mu is too short, you won't get reliable help without providing your table structure.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号