SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


multiple relationships


multiple relationships

Author
Message
weston_086
weston_086
SSC-Enthusiastic
SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)

Group: General Forum Members
Points: 123 Visits: 464
how we can solve this problem
Cross Product
T_VOL_USAGE

VOL_name NODE-Name
V1 B
V12 F
V3 F
V2 C
V2 D
V3 E
i want a query that will dynamically eliminate the multiple relationships and resulting in V1, B as the only 1 to 1 Relationship
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26540 Visits: 17557
You are going to have to provide some level of detail in order for anybody to have a chance here. There just simply isn't enough information in your post. Take a look at the first link in my signature about best practices on posting questions.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
J Livingston SQL
J Livingston SQL
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5535 Visits: 35462
here's a thought...any good?



USE [tempdb]
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_VOL_USAGE]') AND type in (N'U'))
DROP TABLE [dbo].[T_VOL_USAGE]
GO

CREATE TABLE [dbo].[T_VOL_USAGE](
[VOL_NAME] [nvarchar](5) NULL,
[NODE_NAME] [nvarchar](5) NULL
) ON [PRIMARY]

GO

INSERT INTO [dbo].[T_VOL_USAGE]([VOL_NAME], [NODE_NAME])
SELECT 'V1', 'B' UNION ALL
SELECT 'V12', 'F' UNION ALL
SELECT 'V3', 'F' UNION ALL
SELECT 'V2', 'C' UNION ALL
SELECT 'V2', 'D' UNION ALL
SELECT 'V3', 'E'

SELECT TV.VOL_NAME,
TV.NODE_NAME
FROM T_VOL_USAGE TV
INNER JOIN (SELECT VOL_NAME
FROM T_VOL_USAGE
GROUP BY VOL_NAME
HAVING ( COUNT(*) = 1 )) A ON TV.VOL_NAME = A.VOL_NAME
INNER JOIN (SELECT NODE_NAME
FROM T_VOL_USAGE
GROUP BY NODE_NAME
HAVING ( COUNT(*) = 1 )) B ON TV.NODE_NAME = B.NODE_NAME



________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

weston_086
weston_086
SSC-Enthusiastic
SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)SSC-Enthusiastic (123 reputation)

Group: General Forum Members
Points: 123 Visits: 464
thanks it works
ernesto.felix.city
ernesto.felix.city
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 37
I am just curious for why you included 'brackets' [ inside every object in your query solution?
I am a newbie and I am just confused for why it looks so complicated with all those brackets?
Will it be possible to successfully execute the query without including the brackets and just keeping it simple?
Thank you
Highest regards
Ernesto
pdanes
pdanes
Right there with Babe
Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)Right there with Babe (746 reputation)

Group: General Forum Members
Points: 746 Visits: 1354
ernesto.felix.city (10/26/2012)
I am just curious for why you included 'brackets' [ inside every object in your query solution?
I am a newbie and I am just confused for why it looks so complicated with all those brackets?
Will it be possible to successfully execute the query without including the brackets and just keeping it simple?
Brackets are necessary if you have 'bad' object names, i.e. names with spaces, foreign characters and such. If the names are well constructed, brackets are not necessary, but they never hurt. Some people just get in the habit of using them as a precaution, some people put them in posts to keep your (potentially) badly named object from breaking the code they post for you, when you change object names from their examples to your own.
dwain.c
dwain.c
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7475 Visits: 6431
I am not 100% sure given the limited sample data but this may also work:


SELECT VOL_NAME, NODE_NAME=MAX(NODE_NAME)
FROM T_VOL_USAGE
GROUP BY VOL_NAME
HAVING COUNT(*) = 1
INTERSECT
SELECT VOL_NAME=MAX(VOL_NAME), NODE_NAME
FROM T_VOL_USAGE
GROUP BY NODE_NAME
HAVING COUNT(*) = 1





My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search