Join three tables with one of them not having a primary key

蹲街弑〆低调 提交于 2019-12-14 03:06:13

问题


I have three tables that i would like to join up together.

Domain table
-domainid - Primary key

DomainRegion table
-domainid - Don't have a Primary Key or Foreign Key
-dombegin
-domend

DynDomrun table
-ddid - Primary Key
-confid1
-confid2

"domain.domainid", "domainregion.domainid" and "dyndomrun.ddid" have the same type of data types, "character varying".

Now, the problem is that "domain.domainid" and "domainregion.domainid" has two extra characters in it that i can't seem to do a join with "dyndomrun.ddid".

However, "domainid" is related to "ddid", just that "domainregion.domainid" is not assigned a primary key or a foreign key and i need some fields from that table to join up with the others.

In the end, I need to have a single, full table listing the "dyndomrun.ddid, domainregion.dombegin, domainregion.domend, dyndomrun.confid1, dyndomrun.confid2".

I have tried using where ("domain.domainid",8)=left("dyndomrun.ddid",8), it gave me an error stating

ERROR: function left(character varying, integer) does not exist HINT: No function matches the given name and argument types. You may need to add explicit type casts.

I have tried using joins, and other sql statements and they all don't seem to work.

Any ideas as to how to solve this problem?

Thank you.


回答1:


In addition to what I answered here, you also need to read up on the syntax of identifiers in PostgreSQL.

This:

"domain.domainid"

would have to be

"domain"."domainid"

Or better yet, simply:

domain.domainid


来源:https://stackoverflow.com/questions/8645230/join-three-tables-with-one-of-them-not-having-a-primary-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!