[Webdev] SQL question
Martin
kitten at psophos.com
Thu Aug 31 00:12:38 IST 2000
> :>If I want to search pretty much every field of a mysql table, do I have
> :>to just to put in a big long WHERE clause or is there some quicker way?
>
> As far as I know, yes,
> SELECT * from table_name;
> gives you all the fields, but if you want to do some more groovy searching
> then you're going to need to stick in a conditional, like WHERE AND or WHERE
> OR.
To make the search quicker you could put an index on every
column in the table. Not recommended though. Searching is nice &
fast but inserting data is painfully slow as all the indexes
must be updated too.
You could do it if you must search every field in the table &
the data in the table is static, or changes very little.
Otherwise don't.
> :>Or for that matter, is there a simple way of searching more than one
> :>table?
>
> There is indeed. They're called "table joins"
> For example say you have the following tables
>
> table userlist:
> user id pass name email
>
> table bookmarks:
> user url desc category
>
> SELECT bookmarks.url FROM bookmarks, userlist WHERE bookmarks.user =
> userlist.user;
>
> The above should work on most systems, but there is an ANSI SQL standard for
> doing inner joins, and the proper syntax is something like...
>
> SELECT bookmarks.url FROM bookmarks INNER JOIN userlist ON bookmarks.user =
> userlist.user;
A join/2/3 may help you. If you have to search every field in
the table then the design of the table/database may need to be
revised.
Some of this stuff is more art than science (well it seems that
way at times :-). Good luck.
Martin
More information about the Webdev
mailing list