[Wolves] Happy Christmas ...and help me with this mysql query

Andy Smith andy at strugglers.net
Thu Dec 27 16:50:56 UTC 2012

Hi Wayne,

On Thu, Dec 27, 2012 at 04:46:53PM +0000, Wayne Morris wrote:
> Happy Xmas ;-)
> Now pay for it with :

Thanks for putting the wishes first.. I've had worse:



> How do I select from
> Item      Parts
> Item A   Part1
> Item A  Part2
> --------    -------
> ItemA   Part11
> ItemA    Part 12
> ItemB    Part1
> ItemC    Part1
> ItemD    Part 1
> ItemD    Part 2

I am having great difficulty understanding your table structure..

> I want to select only the first part for each item, but if I do
> select Item where Parts like '%1%', I get Part1 and Part11 and Part
> 12, etc

..but if it is really like this, with you have to do partial text
matches, then your structure is wrong in my opinion, and should be

Can you show us the actual schema of your tables ("show create table
yourtablename", for example) and what you want to select out of them?

You can limit your matches to 1 with something like:

    SELECT Item FROM yourtablename WHERE Parts LIKE '%1%' LIMIT 1

but this is unlikely to be the best way to do it so better if you
explain more.


http://bitfolk.com/ -- No-nonsense VPS hosting

<Eyecon> freecycle is for dating single mothers
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://mailman.lug.org.uk/pipermail/wolves/attachments/20121227/cf43838c/attachment.pgp>

More information about the Wolves mailing list