如何使用sql选择基于其组的特殊联系人列表 [英] how do select special contact list based on thier group with sql

查看:72
本文介绍了如何使用sql选择基于其组的特殊联系人列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



i有2张桌子:



1-联系

2-团队



联系我有一个名字groupid和其他字段的字段



在组中我有一个ID和组名



现在:



i想在csharp&中查询这样的查询;访问项目:



用户选择想要查看其他联系人的最喜欢的组



例如:用户选择组列表中的a,b,c



现在程序显示组a,b,c中存在的联系人





----



i写了这个查询并且工作正常但是这个没有groupname列



hi all

i have a 2 table :

1- contact
2- group

in contact i have a field with name groupid and other fields

in group i have a ID and groupname

NOW :

i want a query like this in csharp & Access Project :

user select favorite group that want views thier contacts

for example : user select group a ,b , c in list

now program shoud show contacts that exists in group a ,b , c


----

i writed this query and work fine but this have not a groupname column

Select distinct tbl_contact.firstname,tbl_contact.lastname,tbl_contact.company,tbl_contact.address1,tbl_contact.address2,tbl_contact.fixtel1,tbl_contact.fixtel2,tbl_contact.fixtel3,tbl_contact.fixtel4,tbl_contact.mob1,tbl_contact.mob2,tbl_contact.fax,tbl_contact.email,tbl_contact.website,tbl_contact.photo,tbl_contact.description from tbl_contact where groupname='a' and groupname='b' and groupname='c'



i want add group name and sort result by group name like below :

a contact1
a contact2
a contact3
a contact4

b contact5
b contact6
b contact7
...





请帮帮我



非常感谢



please help me

thanks a lot

推荐答案

试试这个:



Try this:

SELECT groupname, firstname, lastname...
FROM tbl_contact
WHERE groupname ='a' OR groupname ='b' OR groupname ='c'
ORDER BY groupname, lastname, firstname 


请尝试以下



Please try the following

SELECT G.GroupName
    ,C.Firstname
    ,C.LastName
FROM
GROUP G
JOIN Contact C ON G.Group_ID = C.Group_ID
ORDER BY G.GroupName


这篇关于如何使用sql选择基于其组的特殊联系人列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆