Query part of a MySQL return

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Query part of a MySQL return

Post by Jr »

Ok, I think my brain is officially off being memorial day weekend or something but I'm trying to do a simple database query but I want to search through the query results to see if all or "part" of the results match my query. I can get the "all" part with a normal query (like below) but how do I search to see if only part of the retults match?


$my_link_query = mysql_query( "SELECT * FROM mydb WHERE link_name='$query'" );

Thanks,
Jr-
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Possibly using LIKE:

Code: Select all

SELECT
 somefield
, someotherfield
FROM sometable
WHERE searchfield LIKE '%{$query}%'
;
Essentially returns records with `searchfield` that matches characters before or after the search string.

MySQL Manual: String Comparison Functions
Post Reply