MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 5th, 2013, 05:20 AM
jt-developer jt-developer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 19 jt-developer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 50 sec
Reputation Power: 0
Need help with best technique for this retrieval...

Hi all. I have a table that contains records which are related to various multiple ids, ie record #1 is related to id 10,11,12 and 51,52,53. Currently the data is being stored as follows

ID | Record Name | Related ID
1 | some name | 10-12&51-53

...the Related ID column you'll notice I've written using a "-", meaning "from A-B", and a "&" meaning "and".

Is there any way I can search this table and find a related ID that is within that group, id find Record Name where Related ID=11?

thanks all

Reply With Quote
  #2  
Old February 5th, 2013, 05:35 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,853 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 13 h 56 m 19 sec
Reputation Power: 813
Hi,

Quote:
Originally Posted by jt-developer
Is there any way I can search this table and find a related ID that is within that group, id find Record Name where Related ID=11?


Nope, because what you're doing there isn't how the relational model works.

The first thing you need to do is repair your data according to the first normal form. After that, you can start querying your database.

Reply With Quote
  #3  
Old February 5th, 2013, 05:47 AM
jt-developer jt-developer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 19 jt-developer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Hi,



Nope, because what you're doing there isn't how the relational model works.

The first thing you need to do is repair your data according to the first normal form. After that, you can start querying your database.


Thanks, so I just need to pull those id lists out and insert them as single lines in another table such as 'associated_ids'? Makes sense, but I'm not sure what the mysql call would be to retrieve multiple rows relating to one id. Do you know what syntax I should be using for that?

Reply With Quote
  #4  
Old February 5th, 2013, 05:57 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,853 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 13 h 56 m 19 sec
Reputation Power: 813
Quote:
Originally Posted by jt-developer
Thanks, so I just need to pull those id lists out and insert them as single lines in another table such as 'associated_ids'?


Yes.



Quote:
Originally Posted by jt-developer
Makes sense, but I'm not sure what the mysql call would be to retrieve multiple rows relating to one id. Do you know what syntax I should be using for that?


Not sure what you mean by that. It's a standard query:
Code:
SELECT
	related_id
FROM
	related_ids
WHERE
	record_id = ...

Reply With Quote
  #5  
Old February 5th, 2013, 07:20 AM
jt-developer jt-developer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 19 jt-developer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Not sure what you mean by that. It's a standard query:
Code:
SELECT
	related_id
FROM
	related_ids
WHERE
	record_id = ...


Sorry, was thinking a bit to far ahead (the actual sql is part of a larger search).

thanks for the info.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Need help with best technique for this retrieval...

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap