Jump to content

[SOLVED] Question about using LIKE during ON queries


Buchead

Recommended Posts

Hello...

This is more of a question to find out if a query is possible.

In one table I have columns for ID (unique, incremental) and name. In another table I have another column for ID (unique, incremental) and one the called info. This contains various IDs from the first table in the format of ;1;20;23; etc.....

What I'm attempting to do is pull the names from the first table where that ID is in the info column of the 2nd table, depending upon the ID of the 2nd table specified.

I have the query:
[code]SELECT a.name FROM `table1` AS a INNER JOIN `table2` AS b ON a.ID=b.info WHERE b.ID='$ID'[/code]

The problem I'm experiencing is how to specify a LIKE in the a.ID-b.info part. If I wanted to simply select date from table2 I could use WHERE b.info LIKE '%$value%', but can't get wildcards to work around b.info (if that's possible at all).

I can't really specify where any in table2 is like table1 ID as if searching on an ID of 1 it would give any result containing 1.

Is what I want to achieve possible?

Thanks.
Link to comment
Share on other sites

Cool. Thanks for that but 2 questions:

1) any idea what problems I could run into, and
2) what's a better way to store the IDs?

I could have an undetermined number of IDs to store, and rather than create a large number of columns, of which many would remain empty, I thought it best to be stored in one column. Or is it the ';' that will cause the problems?

Thanks.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.