Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Csharp.net
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
Posted 25-Jun-13 9:43am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this:
 
SELECT groupname, firstname, lastname...
FROM tbl_contact
WHERE groupname ='a' OR groupname ='b' OR groupname ='c'
ORDER BY groupname, lastname, firstname 
  Permalink  
v2
Comments
Member 9243373 at 25-Jun-13 16:14pm
   
doesnt word my friend ...
Maciej Los at 25-Jun-13 16:17pm
   
What doesn't work?
Mike Meinz at 26-Jun-13 9:30am
   
In the Where clause, the AND operators should be OR operators.
Maciej Los at 26-Jun-13 9:33am
   
You're right! Thanks Mike ;)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 386
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 215
3 /\jmot 189
4 Praneet Nadkar 173
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100