鑑於表創建SQL和插入SQL,我將如何生成一個查詢以特定方式顯示信息?如何使用內部連接查詢多個表?
CREATE TABLE cities (
id serial NOT NULL UNIQUE PRIMARY KEY,
iname varchar(100) NOT NULL UNIQUE
)
CREATE TABLE suburbs (
id serial NOT NULL UNIQUE PRIMARY KEY,
icity integer REFERENCES cities (id),
iname varchar(100) NOT NULL UNIQUE
)
CREATE TABLE type (
id serial NOT NULL UNIQUE PRIMARY KEY,
iname varchar(100) NOT NULL UNIQUE
)
CREATE TABLE sale (
id serial NOT NULL UNIQUE PRIMARY KEY,
iname varchar(100) NOT NULL UNIQUE
)
CREATE TABLE estate (
id serial NOT NULL UNIQUE PRIMARY KEY,
icity integer REFERENCES cities (id),
isuburb integer REFERENCES suburbs (id),
itype integer REFERENCES type (id),
isale integer REFERENCES sale (id),
idescription text,
itimestamp timestamp DEFAULT CURRENT_TIMESTAMP
)
INSERT INTO cities (iname) VALUES ('Johannesburg');
INSERT INTO suburbs (icity, iname) VALUES (1, 'Westbury');
INSERT INTO type (iname) VALUES ('Room');
INSERT INTO sale (iname) VALUES ('Rent');
INSERT INTO estate (icity, isuburb, itype, isale, idescription) VALUES (1, 1, 1, 1, 'A Nice place in a real bad neighbor hood');
現在我希望表格中的數值通過它們表示的字符串值來顯示。
E.G 1約翰內斯堡,韋斯特伯裏,房間,出租,說明
將SQL查詢是這個道理,我在使用PostgreSQL更關心。
字面上**所有值的**,像每一個單柱?這是MySQL還是PostgreSQL? – Yuck 2012-03-06 15:48:14
你想在每個表的所有列上做一個'JOIN'?任何你想要這樣做的理由? – Karlson 2012-03-06 15:50:38
@Yuck我正在從使用MySQL轉換到PostgreSQL,所以它會是postgreSQL,那麼從每個表的某些值中,某些表被用作參考表。 – Aaron 2012-03-06 15:50:51