mohansinfh — 2010-11-27T01:15:17-05:00 — #1
Please someone tell me the command for searching in whole table of a database,
like If I want to search whole table (not by any single field or column)
For example, I want something similar command to this
SELECT * FROM `school_table` like '%mohan%'
Please note, I know the other command for searching but that is only for searching in any particular row, for example.
SELECT * FROM `school_table` where name like '%mohan%'
system — 2010-11-27T01:28:56-05:00 — #2
can you give an example of what you want returned from the search?
mohansinfh — 2010-11-27T01:34:13-05:00 — #3
yes sure, For example, I want to return all the columns (e.g. ID, Name etc.) of a table, where any field name is consisting of my name.
My name is mohan.
So, if a table consists of mohan anywhere in it, it should return me that column.
system — 2010-11-27T01:46:23-05:00 — #4
ok, say your table has 3 columns in it - col1, col2 and col3
select * from tblName
where col1 like '%mohan%' or col2 like '%mohan%' or col3 like '%mohan%';
will return all the columns where mohan is in any of them.
mohansinfh — 2010-11-27T03:05:56-05:00 — #5
What is the command of searching this thing in a table of mysql?
For example, I have a record mohan in one of my mysql-table, and when i search the database by the name mohan, it returns the rows wherever the column has name mohan in it.
select * from names where name like '%mohan%'
This is very simple.
But I felt said when I searched by the name moh an, there was no rows returned.
and the same thing happened when i searched moh-an.
select * from names where name like '%mo han%'
select * from names where name like '%mo-han%'
Is there any way to search all the characters in that column name and figure out what i want?
r937 — 2010-11-27T05:11:20-05:00 — #6
not based on the example you gave, no
r937 — 2010-11-27T05:27:12-05:00 — #7
well, for starters, you wouldn't need to look into any column that is numeric, like the id column
so you wouldn't search all the columns, just the string ones
mohansinfh — 2010-11-27T05:35:17-05:00 — #8
Thanks to all of you.
I got the way.
mohansinfh — 2010-11-27T05:36:36-05:00 — #9
Oh sir, some other method to get some similar results ?????
r937 — 2010-11-27T05:55:17-05:00 — #10
you could do this --
WHERE name LIKE CONCAT('%',REPLACE(REPLACE('mo han',' ',''),'-',''),'%')
but you should probably remove the spaces and dashes in your application language (php?) before searching
mohansinfh — 2010-11-27T06:01:28-05:00 — #11