aveach Posted January 4, 2003 Share Posted January 4, 2003 I\'m new and i\'m trying to write a query that searches all columns for a certain variable without writing out the name of every column in the table. Is there a command like SELECT * FROM mytable WHERE * LIKE\'%...%\' ? That would search the entire table for a value? I dont want to write SELECT * from mytable WHERE field1 like \'%somevar%\' OR field2 like \'%somevar%\' OR ...... Or even a way of indexing the whole database in one column then i could search that column in my query? How do i go about this. Thanks[/i][/u] Quote Link to comment https://forums.phpfreaks.com/topic/16-search-all-fields/ Share on other sites More sharing options...
pallevillesen Posted January 6, 2003 Share Posted January 6, 2003 The answer is NO. There is no smart way to search all coloumns for a given string. But why would you do that? (If you really want to, then do as you suggest in your second line.) You COULD combine all coloumns into one large string and put that into a new coloumn - but that is not nice at all. The idea behind having a database disappears if you start collapsing information into one huge pile and then searches it like that. I\'m curious - what kind of data would you like to search in such a manner ? P., denmark I\'m new and i\'m trying to write a query that searches all columns for a certain variable without writing out the name of every column in the table. Is there a command likeSELECT * FROM mytable WHERE * LIKE\'%...%\' ? That would search the entire table for a value? I dont want to write SELECT * from mytable WHERE field1 like \'%somevar%\' OR field2 like \'%somevar%\' OR ...... Or even a way of indexing the whole database in one column then i could search that column in my query? How do i go about this. Thanks[/i][/u] Quote Link to comment https://forums.phpfreaks.com/topic/16-search-all-fields/#findComment-41 Share on other sites More sharing options...
pallevillesen Posted January 8, 2003 Share Posted January 8, 2003 Also sent by mail to original questioner... Ok, just came up with an idea... You MAY be able to combine all fields in the search using select * from table where concat(field1, field2, field3,....field20) like %$searchterm%; (I\'m not sure if I remeber correctly with concat but anyway there is a mysql order for combining fields. I\'m not sure about speed though - it might be quite slow... CORRECTION: I just checked my own code... It works. (This is for a adress database and dive logging - danish field names, sorry about the confusion). $sql->Query("SELECT p.Prs_PersonID, CONCAT(p.Prs_Fornavn,\' \',p.Prs_Efternavn), p.Prs_Status, p.Prs_Email, p.Prs_WWW, COUNT(tbl_Noter.Note_NoteID), tbl_Dykkererfaring.Dykef_LoggedeDyk FROM (tbl_Person AS p LEFT JOIN tbl_Noter ON p.Prs_PersonID = tbl_Noter.Note_PersonID) LEFT JOIN tbl_Dykkererfaring ON p.Prs_PersonID = tbl_Dykkererfaring.Dykef_PersonID WHERE (// HERE IT COMES!!! ((concat(p.Prs_Fornavn,\' \',p.Prs_Efternavn)) like \'%$navn%\') AND (p.Prs_Status like \'$status\') ) GROUP BY p.Prs_PersonID ORDER BY $sortby "); P. Quote Link to comment https://forums.phpfreaks.com/topic/16-search-all-fields/#findComment-61 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.