Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / July 2008

Tip: Looking for answers? Try searching our database.

Can it be solved by a Query only ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick - 01 Jul 2008 10:44 GMT
There are 2 tables in an application system.

The first table "grpmem" contains both group_id and member fields.

select id, c_last_name from ctct where id = 735169
id                    c_last_name
735169            Property Service Officer

In the second table "ctct", it contains both data for Role and Member (First
Name and Last Name).

select id, c_last_name from ctct where id = 735169
id                    c_last_name
735169            Property Service Officer

I have created 2 queries so that the first one retrieve the Group Name while
the second one retrieve the Member Name.   Then I export it to an Access
Database and perform a LEFT JOIN (There are more Groups than Members).

The result I would like to get is as follow (This is because the Role
returned is more than the rows of Name)
780205            Property Service Officer      James       Pang
780256            Property Service Supervisor
780257            Property Service Manager      Gary        Poon

I just wonder whether it can be achieved by running a SQL Script by using
LEFT JOIN ?

Thanks
Patrick
Uri Dimant - 01 Jul 2008 11:54 GMT
Patrick
> The first table "grpmem" contains both group_id and member fields.
>
> select id, c_last_name from ctct where id = 735169
> id                    c_last_name
> 735169            Property Service Officer

You said that it is 'grpmem' table but show us the second one.Can you post
sample data along with tables structure?

> There are 2 tables in an application system.
>
[quoted text clipped - 28 lines]
> Thanks
> Patrick
Patrick - 01 Jul 2008 12:08 GMT
Dear Uri,

Sorry for missing the grpmem table.

select * from grpmem where id = 780205
id                    Group Id         member
780205            735169            437418

Thanks

> Patrick
>> The first table "grpmem" contains both group_id and member fields.
[quoted text clipped - 38 lines]
>> Thanks
>> Patrick
Uri Dimant - 01 Jul 2008 12:22 GMT
Hi
>>> I just wonder whether it can be achieved by running a SQL Script by
>>> using LEFT JOIN ?

Again , can you post CREATE TABLE....+INSERT INTO ... VALUES for testing

SELECT * FROM grpmem  LEFT JOIN ctct  ON grpmem.id=ctct.id

> Dear Uri,
>
[quoted text clipped - 48 lines]
>>> Thanks
>>> Patrick
Patrick - 01 Jul 2008 12:30 GMT
Dear Uri,

Thank you for your advice and I will supply more information tomorrow.

Thanking you in anticipation.

The queries should be
select * from grpmem where id = 780205
id          Group Id    member
780205            735169            437418

select id, c_last_name from AHD.ctct where id = 735169
id          c_last_name
735169            Property Service Officer

select id, c_first_name, c_last_name from ctct where id = 437418
id          c_first_name      c_last_name
437418            James       Pang

Thanks
Patrick

> Hi
>>>> I just wonder whether it can be achieved by running a SQL Script by
[quoted text clipped - 57 lines]
>>>> Thanks
>>>> Patrick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.