what database system are you using?
Main Topics
Browse All TopicsI have a complex (to me) query that I am building. Here are my tables and fields I need to work with...
[loadboard]
originstateid, destinationstateid
[states]
stateid, regionid
[text]
outof, goingto
I will try to explain....
loadboard.originstateid & loadboard.destinationstate
Each unique states.stateid is assigned a states.regionid value
text.outof & text.goingto both contain a comma seperated list of values (1,2,3, etc) corresponding to states.regionid 's.
I need to find records from the text table where loadboard.originstateid's corresponding states.regionid is in the text.outof value list and the loadboard.destinationid's corresponding states.regionid is in the text.goingto value list.
How might I do this? I hope I explained it ok to understand. thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
this works in sql server. i'm not sure if it translates completely to mysql.
if this runs, you could then join the loadboard table on to it as a derived table or a temp table.
SELECT
text.outof,
text.goingto,
OutOfStates.regionid OutOfRegionId,
OutOfStates.stateid OutOfStateId,
GoingToStates.regionid GoingToRegionId,
GoingToStates.stateid GoingToStateId
FROM
text
INNER JOIN states AS OutOfStates
ON
text.outof LIKE RTRIM(CAST(OutOfStates.reg
text.outof LIKE '%,' + RTRIM(CAST(OutOfStates.reg
text.outof LIKE '%,' + RTRIM(CAST(OutOfStates.reg
INNER JOIN states AS GoingToStates
ON
text.goingto LIKE RTRIM(CAST(GoingToStates.r
text.goingto LIKE '%,' + RTRIM(CAST(GoingToStates.r
text.goingto LIKE '%,' + RTRIM(CAST(GoingToStates.r
Business Accounts
Answer for Membership
by: danrosenthalPosted on 2006-10-04 at 16:15:12ID: 17664457
Consider changing your table structure before continuing.
Add another table to hold the individual comma seperated values as individual values in a new table.
For instance if you have values "1,4,23" in your outof field, instead enter them as 3 records of "1", "4", and "23" in a new table referenced by a unique id to the text table.