PDA

View Full Version : Searching a table technique


fido_glc
03-25-2009, 06:11 PM
Hello.

I have an SQL database with a table that has about 20 columns and about 30 rows.

I need to perform a search on the whole table based on the values from one row: I need to find what other rows have similar values with the row that I base my search on. The similarities can vary from 1 column to all 20 columns.


I am not very experienced with SQL, I only know the some basic things and I need help in writing the code to perform the search (PHP).

Please help.


Thank you.

yell0wdart
03-25-2009, 08:10 PM
What exactly are you trying to search for, and how are you comparing?

You can pass in a value and use the LIKE (http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html) keyword to do your column comparisons for you.


SELECT *
FROM `my_table`
WHERE `column_1` LIKE '%bleh%'

-- % is a wildcard where SQL string comparisons go.
-- Anything can come in place of the '%'.

-- In the example, '%bleh%' could match results to:

-- * 'asfasfblehasdfasdf'
-- * 'my name is bleh'