I'm trying to delete records from a table that is getting to much spam. So, the idea is delete all records that don't have email from hotmail, gmail or yahoo. But my sql looks like is returning some hotmail records:
SELECT *
FROM `users`
WHERE email NOT LIKE '*hotmail.com*'
AND email NOT LIKE '*gmail.com*'
AND email NOT LIKE '*ymail.com*'
Applying the OR condition returns the same result. Can you guide to the right direction?
The query should look like this
SELECT *
FROM `users`
WHERE email NOT LIKE '%hotmail.com%'
AND email NOT LIKE '%gmail.com%'
AND email NOT LIKE '%ymail.com%'
You have to replace * by %
If SQL LIKE clause is used along with % characters then it will work
like a meta character (*) in Unix while listing out all the files or
directories at command prompt.
Here's the doc about LIKE in MySQL
SELECT *
FROM users
WHERE email NOT RLIKE '\\#(hotmail|gmail|ymail)\\.com$'
Your query will also return you gmail and ymail
In mysql you have to use % instead of *
So just substitute it and everything will be ok.
Related
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',''));
I have 100 email address in my mysql table and its look like abc#xy.com, fdgf#xy.com, ghfe#xy.com, erekke#xyz.com,tty#xyz.com, ere#xy.com, ect.... I need to change all #xy.com to #xyz.com using mysql query.
Please help me for query
Thanks in advance!
You can try this:
update myTable
set email = replace(email, '#xy.com', '#xyz.com')
where email like '%#xy.com'
I'm trying to update a column used for email in my database with the site id for the same row..
I've tried the following:
UPDATE LOCATIONS
SET email ='se".site_id."#myemail.com'
WHERE customer='MyCustomer' AND site_id='5555';
expecting the email column to be se5555 at myemail.com
but that wasn't the case. Should I use CONCAT?
Use concat function of mysql like this:
UPDATE LOCATIONS SET email = concat('se',site_id,'#myemail.com') WHERE
customer='MyCustomer' AND site_id='5555';
You can definitely use concat(). I also like to use replace() for this type of operation:
UPDATE LOCATIONS
SET email = replace('se<site_id>#myemail.com', '<site_id>', site_id)
WHERE customer = 'MyCustomer' AND site_id = '5555';
This is helpful when you have multiple substitutions -- the first argument is a template so it is easier to see what you are doing and to modify.
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".
I'm currently in hour two of this issue, I can't explain it so I will simply show what is going on. I don't know if this matters at all, but I am using the linkedIN API to retrieve a user's linkedIn unique ID.
In English, what I'm doing:
User Signs in with LinkedIn
I read-in user's LinkedIn ID (returned from the API)
If ID exists in database, say "hello", if not, show them a form to register
The issue I am having:
The following line works and properly returns the 1 user I have in the database with a linkedIn ID of OtOgMaJ2NM
$company_data = "SELECT * FROM s_user WHERE `LI_id` = 'OtOgMaJ2NM'";
The following query returns no results - using the same database with the same record in the table s_user:
$linkedIn_id = "<?js= id ?>";
echo $linkedIn_id;
The following code outputs OtOgMaJ2NM with no trailing spaces.
So far so good ... expcept when I run the query this time using the variable, no records are returned!
$company_data = "SELECT * FROM s_user WHERE `LI_id` = '$linkedIn_id'";
Further notes:
When I echo $company_data the same query is displayed when I use the variable as did when I used the plain text version of the query.
Anyone have ANY ideas?
Thanks,
Evan
I can only assume that when echoing variables it strips the tags, so when you're using it with the query you're actually saying:
$company_data = "SELECT * FROM s_user WHERE `LI_id` = '<?js= OtOgMaJ2NM ?>'";
I could be wrong, but have you tried stripping the tags from the variable?
If you send the variable between the "", the MySQL engine will search for $linkedIn_id literally and not for its content.
Seems you are using php, but I'm not sure about the right syntax. Take a look in the docs.