我只能在一個查詢中創建特定的SQL查詢時遇到問題(我不能兩次訪問數據庫,對於設計體系結構,請相信我)這裏的語句:如何使這個SQL查詢只有一個SELECT
我有四個表: 問題, 位置, 國家, 地區
這是他們的一些領域:
Questions
id
description
Locations
id
type (could be 'country' or 'region')
question_id
country_or_region_id (an id, that holds either the country or the region id)
Countries
id
name
Regions
id
name
我想是這樣的:
例子:
1 What is your name? Venezuela, Colombia South America
格式:
question id, question description, countries, regions
編輯:對於那些誰問,我m使用MySQL
編輯:對於那些說這是一個糟糕的設計:我沒有創造它,我不能改變設計,我只需要這樣做,就像現在這樣。
你到目前爲止嘗試過什麼?你遇到什麼問題?你能提供樣本數據/期望的輸出嗎? –
您如何期望系統知道'Locations'表中的country_or_region_id是國家還是地區ID? – hanleyhansen
@hanleyhansen這是類型字段的用途。但是你沒有從國家到地區的鏈接。 – theB3RV