Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MaxDB - Everything about MaxDB, formerly known as SAP DB
MySQL++ - Programming with the C++ API to MySQL
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
ODBC - ODBC with the MySQL Connector/ODBC driver
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
Getting unique values

Getting unique values

2006-06-29       - By Pooly

 Back
Reply:     1     2     3     4  

Hi,

2006/6/28, Chris Sansom <chris@(protected)>:
> I'm sure this is an elementary problem, but I can't get my head round it.
>
> I have two tables: pix and sections, the relevant bits of which are:
>
> pix (2,421 rows):
> picid       varchar(7)             not null
> sectionid   smallint(5) unsigned   not null
> caption     text                   null
>     picid and sectionid are a joint primary key
>     caption is full text indexed
>
> sections (a mere 152 rows):
> sectionid   smallint(5) unsigned   not null
> title       varchar(63)            not null
> blurb       text                   null
>     sectionid is primary key (auto increment)
>     title and blurb are full text indexed
>
> In pix, there may well be several instances of the same picid, but
> always with a different sectionid (obviously).
>
> The trouble is, this was originally set up with no intention of
> actually searching the tables, but now I want to. And I want to find
> the first instance of each picid that matches the text anywhere in
> caption, title or blurb, and get some other info at the same time.
> Oh, and for the time being it needs to be possible in MySQL 3.23.x.
>
> So far I'm doing a very simple:
>
> SELECT DISTINCT picid
> FROM pix AS p
> INNER JOIN sections AS s ON p.sectionid = s.sectionid
> WHERE caption LIKE '%searchterm%' OR title LIKE '%searchterm%'
>     OR blurb LIKE '%searchterm%'
> ORDER BY picid
>
> then as I loop through the results I'm more or less repeating the
> process to get the other information:
>
> SELECT p.sectionid, caption, title
> FROM pix AS p
> INNER JOIN sections AS s ON p.sectionid = s.sectionid
> WHERE (caption LIKE '%searchterm%' OR title LIKE '%searchterm%'
>     OR blurb LIKE '%searchterm%') AND p.picid = 'picid'
> LIMIT 1

If you know the picid previously retrieved, then the clause (caption
LIKE '%searchterm%' OR title LIKE '%searchterm%' OR blurb LIKE
'%searchterm%') is redundant, isn't it ?

--
http://www.w-fenec.org/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql@(protected)