开发者

SQL query compare and get info based on two tables

I have two tables. Contacts and groupcontacts. I want all contacts from group x listed.

Table A Tablename : contacts Fields : crmcListId crmcId

Table B Tablename: contactgroups Fields : crmcgrId crmcgrContactId crmcgrGroupId

Fiel开发者_运维技巧d crmcgrID = crmListID Field crmcID = crmContactID

I want all contacts from table a belonging to group x to list. From table contactgroups where crmcgrGroupID = x


Do something like :

SELECT c.* FROM Contacts c WHERE c.ID IN (SELECT ContactID FROM groupcontacts) 

OR with a join :

SELECT c.* FROM Contacts c 
INNER JOIN groupcontacts gc ON c.ID = gc.ContactID

You can then add a WHERE clause to select the IDs for a specific group.


Since it's not entirely clear what your tables look like, I'm going to take a shot in the dark here:

Select * 
From Contacts c
inner join GroupContacts gc on gc.ContactID = c.ContactID
where gc.GroupID = x

Just subsitiute x for the real group id

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜