FullText search with additional where - mysql

I'm having trouble working with the match against functionality of MySQL.
I converted my table and a simple query like:
SELECT * FROM 'objectclient_objecten' WHERE MATCH('dh_omschrijving) AGAINST ('these search words');
works! But.. i want to add other "where" elements. Something like:
SELECT * FROM 'objectclient_objecten' WHERE MATCH('dh_omschrijving) AGAINST ('these search words') AND `dh_status` = 1;
But then.. No results. It seems impossible to add something after using match. Is this right? Or is there a workaround?

try that
SELECT * FROM 'objectclient_objecten' WHERE MATCH(dh_omschrijving) AGAINST ('these search words') AND `dh_status` = 1;
^^^^^^^^^^^^^^^^^---without quotes here
MATCH(here columns without quotes) , you are using column between quote.

Related

transfer several parameters from a form into SQL query

i am working on a table that includes a filter function.
For the filter i use a form where i enter the parameters.
Those are added to a string which is my SQL query.
So far it works fine.
There is oine input field where multiple parameters canbe added.
The plan is to seperate them with ; .
For example 520;521;522
My plan was to use str_replace to convert this in to sql Code.
For example
$str = str_replace(";", "" OR ", "520;521;522");
Results in to:
SELECT * FROM MaschinenVorgangslisteMitHV WHERE (VorgangNr LIKE '%520%' or '%522%' or '%523%')
But some how this code does not show the expected results.
I only get results for '%520%'
How do i need to adjust this query in order to have the sql query working?
$str = str_replace(";", "" OR ", "520;521;522");
Results in to:
SELECT * FROM MaschinenVorgangslisteMitHV WHERE (VorgangNr LIKE '%520%' or '%522%' or '%523%')
In another input field i search for names.
Here the query looks like this...
SELECT * FROM MaschinenVorgangslisteMitHV WHERE (Bearbeiter LIKE '%Heine%' OR Bearbeiter LIKE '%Wolf%' OR Bearbeiter LIKE '%Maiwald%')
This works fine!
The multiple like should be written as,
SELECT *
FROM MaschinenVorgangslisteMitHV
WHERE VorgangNr REGEXP '520|522|523';
I believe you need to add VorgangNr LIKE after every OR.

How can I use OR operator with 2 tables?

I'm trying to making a search option for my website project. I have to search 2 columns from 2 tables. After that, I'll write that query in my php code. Then it will list all the data about it. But it seems like I'm doing it wrong. What should I do?
select *
from mudurler,subeler,veriler
where mudurler.sube_id=subeler.sube_id
and veriler.sube_id=subeler.sube_id
and subeler.sube_ad like "%this%" or mudurler.adSoyad like "%that%"
When I go, if there is a valid value on sube_ad it works perfectly. But when i try to put valid value on adSoyad MySQL turns an empty result no matter what the value is.
You would have no problem if you used proper, explicit, standard JOIN syntax:
select *
from mudurler m join
subeler s
on m.sube_id = s.sube_id join
veriler v
on v.sube_id = s.sube_id
where s.sube_ad like '%this%' or
m.adSoyad like '%that%';
May be you should try:
and (subeler.sube_ad like "%this%" or mudurler.adSoyad like "%that%")

MySQL return no results from select * where varchar="" query

I'm having issue with my study project for creating database in MySQL.
I've imported data using LOAD to my created table from a CSV file. Now when I'm executing select * from mytable everything show up perfectly, but when I execute select * from bi_jogging.routes as r where r.Creator_Email="jhenderson7c#bbb.org"
I get nothing.
The email is there, I've tried different syntax options but it seems to be something else, I suspect something with the varchar format, I really have nothing in mind.
For other tables it works fine and others not.
You can try using the query:
select * from bi_jogging.routes as r where r.Creator_Email like "%jhenderson7c#bbb.org%"
If like operator shows the result then there may be white spaces in the email, please double check..
For join try this:
select * from bi_jogging.routes as r join bi_jogging.buddies as b
on b.Email like '%r.Creator_Email%'
I think it should work. Again check with same code.
select * from bi_jogging.routes as r where r.Creator_Email='jhenderson7c#bbb.org'
if [select * from mytable] this works ,then try to copy the email from result and paste it in where clause.
There may be conflicts between quotes.
your table entry contains quotes???
check properly. i think you have quotes in your table entry,so when you try this,
select * from bi_jogging.routes as r where r.Creator_Email like "%jhenderson7c#bbb.org%"
'%' sign matches with any character and you will get the result.
Inside the tablejhenderson7c#bbb.org and "jhenderson7c#bbb.org" are completely different.
I found spaces in the mysql tables after few emails, so I guess that was it. burned 8 hours on this one, thank you all. I could not find the spaces at the end of the mail by looking at it, I had to hit backspace to see that only after two hits the last char is deleted
this helped me : UPDATE bi_jogging.results set Mail_Found = TRIM(Replace(Replace(Replace(Mail_Found,'\t',''),'\n',''),'\r',''));

Query for exact word search

hope that you are doing fine
I am having very hard time writing a query
Here is my question explained
i have a database table say "jreviews_content" which has a field named "jr_produits"
In "jr_produits" the data is is the format *ryan-decosta*tom-gosling* so i want a search query that is exact word based i.e if the user type "rya" the mysql should not return anything
but if the user type ryan then it should return the row likewise if the user type "gos" the mysql should not return anything
but if the user type gosling then it should return the row where ryan and gosling are the exact words
the query that i am writing are
SELECT *
FROM `jreviews_content`
WHERE jr_produits LIKE '%*ryan-%' or jr_produits LIKE '%-ryan*%'
or jr_produits LIKE '%*ryan*%' or jr_produits LIKE '%-ryan-%';
I want that to be done in some other way that is more efficient(either by regular expression or any other method)
SELECT * FROM `jreviews_content` WHERE jr_produits REGEXP '^[*-]ryan[*-]$'
It doen't fetch anything
neither does
SELECT * FROM `jreviews_content` WHERE jr_produits like '%[*-]ryan[*-]%'
Please suggest something
Try the MySQL regex word boundary markers. They're documented about halfway down this page:
SELECT *
FROM jreviews_content
WHERE jr_produits REGEXP '[[:<:]]ryan[[:>:]]'
Note that I don't have MySQL access today, so this is untested.
Also heed what #user1032531 said. Records with values like *ryan-decosta*tom-gosling* almost always mean "bad design".

Exact word match (non-English characters)

I have a table in my Mysql db (utf-8). I want to get exact word matches from this table.
My query is:
SELECT matched_rows FROM MY_TABLE WHERE string = 'MY_STRING'
Problem is when I search for 'ağaç' (tree in English) I got all rows with ağaç, agac, ağac, agaç.
what I want to get is only 'ağaç' not the rest. I also don't want results with something agac.
How do I get this effect?
i followed #gintas answer and made some modifications. in the end this one worked for me:
SELECT ROWS FROM MY_TABLE WHERE CONVERT(string_field_name USING latin5) = CONVERT('MY_STRING' USING latin5)
You should try defining collation in the query
SELECT matched_rows FROM MY_TABLE WHERE string = 'MY_STRING' COLLATE utf8_general_ci
SELECT * FROM users WHERE email REGEXP '[[:<:]]abhi[[:>:]]'
try this link on SO i think you didnt try this?
LINK: url