Hi...
I am using following query to get data from a table

select * from emp where ename regexp 'rajkiran'

It will return only the rows with ename=rajkiran

but I want to select all the rows with ename =raj kiran & ename=rajkiran using a single query

Recommended Answers

All 7 Replies

Try this one to match both:

select * from emp where ename regexp 'raj ?kiran'

Thanks.
How to generalize this query to use with a search engine?

How to generalize this query to use with a search engine?

Specify what you mean.

I have a search engine to search records from mysqldb.

The script used as follows.

$text=$_REQUEST['txt'];
    $q="select * from table where field regexp '$text' ";

I want to get all records from database with and without space character.

For example If $text="KG 1957" or $text="KG1957"
I want all the records containing KG 1957 & KG1957

If you are using a fixed format like that: create a new variable from the first two characters. Then add the space and the question mark. Then add the remaining characters. Then use the new variable in your query.

You have to code that business logic, or allow input of a regex in the editbox.

Search text is not in fixed format.
It varies.
How to change the query to select the data with all possible formats..

There is no one regex that can guess your requirements. You can add the ? after every character though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.