iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2004, 05:01 PM
WebProWorld Member
 
Join Date: Feb 2004
Posts: 52
redstarfcs RepRank 0
Default where field in() problem

I need to select some information that are in a database..I have category field that contain the numbers of some categories, this field is a text field

I need to select category 5

My database structure is:

id---name-------category
1 Test 5
2 Good 12 15 7 5
3 Test 2 123 15 10
4 Test 3 33 424
5 Test New
6 Better 12


I use the following query:

select id from db_table where category in('','5')

MySQL engine select only id=1, why it doesn't select also ids: 2 and 5
Reply With Quote
  #2 (permalink)  
Old 10-21-2004, 02:46 AM
WebProWorld New Member
 
Join Date: Oct 2004
Location: sb in us
Posts: 12
dr.p RepRank 0
Default

Code:
select id from db_table where category in('','5')
This code will match against the entire`category` field, not just part of it. I assume from that example data that your `category` fields contains one or more category numbers separated by spaces.

I would use something like the following:

Code:
Select id From db_table Where category REGEXP "(^| )(5)( |$)"
If you want to select categories 5, 2 and 3, you can then do:

Code:
Select id From db_table Where category REGEXP "(^| )(5|2|3)( |$)"
I suggest you read carefully the SELECT function details in the MySQL manual.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:25 AM.



Search Engine Optimization by vBSEO 3.3.0