![]() |
|
|
| Subject:
Many to many cross reference query
Category: Computers > Programming Asked by: goose_man-ga List Price: $10.00 |
Posted:
03 Feb 2006 06:05 PST
Expires: 06 Feb 2006 04:49 PST Question ID: 440890 |
|
| There is no answer at this time. |
|
| Subject:
Re: Many to many cross reference query
From: daniel_dearlove-ga on 03 Feb 2006 10:00 PST |
The assumption seems to be the links are bi-directional. If you
reform the problem:
1 | a
1 | b
1 | (c)
1 | d , etc
as a list of one-way associations:
a -> b
a -> c
a -> d
b -> a
b -> c
b -> d
c -> a
c -> b
c -> d
d -> a
d -> b
d -> c, etc
then put all the one-way associations into a std::multimap<char,char>
(assuming you use C++). If using C, Pascal, etc., an array of
struct/records/etc like:
struct {
char from;
char to;
} one_way_association;
will work in a similar way (std::vector<one_way_association> in C++ if you prefer).
A std::multimap will automatically put the from-association in order
(to-association might not necessarily be in order by default though).
You can use an appropriate sort() function to put them in order from
C, Pascal, etc.
Then,
std::multimap<char,char> associations;
pair<blah,blah> range = associations.equal_range( 'c' );
int number_of_items = distance( range.first, range.second );
will let you find out how many items 'c' is linked to. It should be
relatively simple whatever associations you want from here. |
| Subject:
Re: Many to many cross reference query
From: daniel_dearlove-ga on 03 Feb 2006 10:07 PST |
same goes for MySQL. Reform the tables as a list of one-way associations and bung in your query: SELECT COUNT( from ) FROM associations WHERE from='c'; If you need to have the table format you specified, I believe you will need to join the table to itself. If I remember correctly (from doing a similar thing in Oracle), you have to give temporary names to the table, like: SELECT COUNT( from.char ) FROM associationlist=from, associationlist=to where from.linkid=tolinkid; or whatever the proper renaming syntax is. |
| Subject:
Re: Many to many cross reference query
From: goose_man-ga on 04 Feb 2006 17:51 PST |
That sounds like a great approach, but as I am new to MySQL, I am struggling with the syntax. Does anyone have advice on how to implement this fully in MySQL? |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |