473,503 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySQL SELECT ?

One of my database tables fields sometimes contains two items. They are
input into the field as "item1, item2" (no quotes). The query I'm using
doesn't seem to pick up any of these multiple items. I'm using

SELECT * FROM table WHERE category = 'item2'

This works fine when item2 is the only thing in the field but not when
it's shared with another value. How can I make the query find all the
instances of item2 in the field even when there are more than one value
in some of the entries?

Jul 17 '05 #1
4 1905
Jack wrote:
One of my database tables fields sometimes contains two items. They are
input into the field as "item1, item2" (no quotes). The query I'm using
doesn't seem to pick up any of these multiple items. I'm using

SELECT * FROM table WHERE category = 'item2'

This works fine when item2 is the only thing in the field but not when
it's shared with another value. How can I make the query find all the
instances of item2 in the field even when there are more than one value
in some of the entries?

MySql supports the LIKE option. So,

SELECT * FROM table WHERE category LIKE '%item2%';

should work. It will be slow since it can't use any indexes to
speed up locating the rows to be retrieved.

HTH
Jerry
Jul 17 '05 #2
On Sat, 13 Mar 2004 15:34:28 GMT, Jack <no*****@please.com> wrote:
One of my database tables fields sometimes contains two items. They are
input into the field as "item1, item2" (no quotes). The query I'm using
doesn't seem to pick up any of these multiple items. I'm using

SELECT * FROM table WHERE category = 'item2'

This works fine when item2 is the only thing in the field but not when
it's shared with another value. How can I make the query find all the
instances of item2 in the field even when there are more than one value
in some of the entries?


Preferably by fixing your database layout. One field should contain one value.

i.e.

Item
----
item_id
category

Containing:

item_id | category
--------+--------------
1 item1, item2

... is wrong. It should be something like:

Item
----
item_id

Containing:

item_id
-------
1

... and a second table:

ItemCategory
------------
item_id

Containing:

item_id | category
--------+--------------
1 item1
1 item2

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #3
I noticed that Message-ID: <40**********************@news.rcn.com> from
Jerry Gitomer contained the following:

SELECT * FROM table WHERE category LIKE '%item2%';

should work. It will be slow since it can't use any indexes to
speed up locating the rows to be retrieved.


For some value of slow

I'm curious why there are multiple items in a field...
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4
Geoff Berrow wrote:
I noticed that Message-ID: <40**********************@news.rcn.com> from
Jerry Gitomer contained the following:

SELECT * FROM table WHERE category LIKE '%item2%';

should work. It will be slow since it can't use any indexes to
speed up locating the rows to be retrieved.

For some value of slow

I'm curious why there are multiple items in a field...

Table Fields: category, text (and several others)

There are about 25 categories and on occasion, the text fits into more
than one category.

Thank you all for your assistance.

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6439
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
0
3510
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
5
3987
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET...
0
4980
by: Fatt Shin | last post by:
Hi, I'm running MySQL 4.0.13, connecting from PowerBuilder 9 using ODCB Connector 3.51. I'm facing a problem where whenever I issue a SELECT COUNT(*) statement from PowerBuilder, I always get SQL...
0
2691
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ...
0
3925
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
3358
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
6
38451
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
1
9547
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.