Monday, 26 August 2013

Sub query or Join in SQL

Sub query or Join in SQL

I have two tables ca_contact, usp_contact
The columns of ca_contact table are
Last_name nvarchr[200],contact_uuid binary[16] ,contact_type [int]
The columns of usp_contact table are
Contact_uuid binary [16],zteam binary[16]
Executing:
SELECT top 2 CA.LAST_NAME , USP.ZTEAM
FROM ca_contact AS CA
JOIN usp_contact AS USP
ON CA.contact_uuid = USP.contact_uuid
AND CA.contact_type = '2308'
Results in
Group Team
Team
PCS_Data Request 0x4B5355B05E7F3F4383FDD4C9C211BC2A
Workplace Services-One Team 0x255C787ED0499841B6FB5003CDE44D8B
I want to replace the Team value with corresponding last_name.
Example
SELECT LAST_NAME FROM ca_contact WHERE contact_uuid =
0x4B5355B05E7F3F4383FDD4C9C211BC2A
Results
LAST_NAME
Solutions Team
Note: for every group record there will be a corresponding one team in
usp_contact which will store in binary format, for every team record there
will detail information ca_contact.
The primary key here is contact_uuid.
Finally I want the output like
Group_name | Team_Name

No comments:

Post a Comment