Yii Framework Forum: sql query/relation problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

sql query/relation problem Rate Topic: -----

#1 User is offline   mithereal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 14-April 10
  • Location:The Radioactive Desert, AZ

Posted 19 April 2010 - 11:57 PM

hello all I have come across a unique situation i cant figure out how to resolve.
i have table here:
---------
|id|data|
|1|cat-dog-bird|
|2|dog-cat-bird|
|3|cat-man-dog|
---------------
how can i make it so
if query is like select * where data == cat-dog-bird or dog-cat-bird or bird-dog-cat
the record ids returned would be 1,and 2 but not id 3.
you see what i mean like a regex separated by a delimiter,
this would probably be more efficient to do in the database eh? anyhow im lost.
0

#2 User is offline   Spyros 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 461
  • Joined: 14-April 09
  • Location:Athens - Greece

Posted 20 April 2010 - 02:27 AM

SELECT * FROM `table` WHERE FIND_IN_SET(data,'cat-dog-bird,dog-cat-bird,bird-dog-cat') > 0;
0

#3 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 21 April 2010 - 01:42 AM

The above will only work if that 'data' column is a SET.
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#4 User is offline   Spyros 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 461
  • Joined: 14-April 09
  • Location:Athens - Greece

Posted 21 April 2010 - 02:07 AM

It works with varchar columns too.
Simply if the column is a SET, the function is optimized.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users