0
id  categories  ext_categories
2      36      17,250
8      20      28
10     17      18

if query categories = 17 I can get results like this

id
2  (ext_categories field)
10

How to query ext_categories for id: 2

Thank you!

2
  • if you want to simply get ext_category for id=2 then try "select ext_categories from table where id=2" Commented Jan 8, 2011 at 7:37
  • Don't put multiple values into a single column! This violates the first normal form of database design - and it's a big no-no. It also creates all sorts of messy code when trying to deal with that kind of data.... just don't do it! Commented Jan 8, 2011 at 8:54

3 Answers 3

1

How is the field ext_categories implemented? For example, are you using a varchar field and pipe-delimited string (of numbers) as values with the strict format

|n|...

so that your table looks like

id  categories  ext_categories
2      36      "|17|250|"
8      20      "|28|"
10     17      "|18|"

instead?

If so, try

select * from table where categories = 17 OR ext_categories like '%|250|%'
Sign up to request clarification or add additional context in comments.

Comments

0

are you looking for group by?

select id,ext_categories From YOURTABLENAME group by id,ext_categories

1 Comment

i guess i got lost with your newly updates on your question, my answer isnt valid now,, please explain more
0

You want to include ext_categories in the results? Or you want a field from a foreign table based on the ID of ext_categories ?

If the later;

$sql = "SELECT * FROM table WHERE categories = 17 OR ext_categories =17 LEFT JOIN ext_category_table on ext_category_table.ext_category = ext_categories"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.