如何加入这两个表我没有得到任何想法
CREATE TABLE entity_social_media (
entity_social_id integer NOT NULL,
entity_id integer NOT NULL,
entity_type character varying(50) NOT NULL,
sm_handle character varying(180),
sm_url character varying(180) NOT NULL,
sm_type_id integer NOT NULL,
created_at timestamp(6) without time zone DEFAULT now() NOT NULL,
updated_at timestamp(6) NULL,
social_media_id character varying(100)
);
CREATE TABLE persons (
person_id integer NOT NULL,
first_name character varying(50) NOT NULL,
last_name character varying(50) NOT NULL,
affiliation character varying(3) DEFAULT 'N/A'::character varying NOT NULL,
state_abbreviation character varying(2) DEFAULT 0 NOT NULL,
district character varying(5),
updated_at timestamp without time zone DEFAULT now() NOT NULL,
middle_name character varying(50),
nickname character varying(50),
status character varying(50) DEFAULT 'active'::character varying
);
如何加入这两个表
答案 0 :(得分:2)
从字段名称中,这两个表中唯一可能的公共/相关字段是entity_id和person_id
您可以按照以下说明加入。
SELECT <entity_social_media.field1>,<entity_social_media.field2>,
<persons.field1>,<persons.field2>
FROM entity_social_media, persons
WHERE entity_social_media.entity_id = persons.person_id;