1
tripmon
SQL Query Help Please
  • 2005/3/17 0:29

  • tripmon

  • Module Developer

  • Posts: 462

  • Since: 2004/2/28


Trying to set up a category WAP solution for piCal.

I have a field that stores category IDs in varchar. If the entry belongs to more than 1 category, it will contain multiple category IDs in the same field, seperated by a comma.

eg. DATA

UID | CATEGORIES
----------------------------
record1 | 00001 | - record1 belongs to 1 cat
----------------------------
----------------------------
record2 | 00001,00002 | - record2 belongs to 2 cats
----------------------------
-----------------------------
record3 | 00001,00002,00003 | - record3 belongs to 3 cats
----------------------------

I need an SQL Query which will return ALL records with any given CATEGORY ID.

eg.
$CATID = 00002
Would return:
record2 | record3

$CATID = 00003
Would return:
record1 | record2 | record3

I don't have experience with delimited string selection/comparison and have spent about 2 hours reading on the MySQL dev site so far...ugh...

If you can fill in the ???, you are my hero:
$result = mysql_query("SELECT id, summary, description, start FROM $prefix"._pical_event." WHERE admission=1 AND $CATID ???????????????????? ORDER BY start ASC")

Thanks for any help and I'll be happy to share the finished product, this is the final query and it's driving me BAT SHIZZY

2
christian
Re: SQL Query Help Please
  • 2005/3/17 0:59

  • christian

  • Just can't stay away

  • Posts: 401

  • Since: 2002/2/24


Hi,

Heu , it is not a academic model (merise).

However you can attempt with LIKE, MATCH, or SET in your where clause.

Best regards

3
tripmon
Re: SQL Query Help Please
  • 2005/3/17 1:33

  • tripmon

  • Module Developer

  • Posts: 462

  • Since: 2004/2/28


While I'm sure LIKE is not the best way to do this, it does work...

I was syntactiaclly challenged when I tried LIKE earlier, realized the typo and violla!

It's working now... Thanks for the help Christian.

Login

Who's Online

131 user(s) are online (44 user(s) are browsing Support Forums)


Members: 0


Guests: 131


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits