MYSQL delete all emails if email_address is in second table [closed] - mysql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 2 email tables. 1 = main email table, 2 = bounce_table.
Field email = unique in both tables.
Tasks = delete from main_email_table where email is in bounce_table.
I have no idea how to make the right call for action for this task.
I hope to get an idea how to solve this.
Thanks

check below query-
DELETE me.* FROM main_email AS me
JOIN bounce_email AS be ON me.email=be.email;

You need a DELETE with JOIN:
DELETE email_table
FROM email_table
INNER JOIN bounce_table ON bounce_table.email = email_table.email

Related

Updating a column with a Count of data from another column in the same table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
As the title suggests, trying to take the count or possibly distinct count of a column, we call it year, to count the number of a years for an individual or populated ID and place it another column in the same table. Here is an idea of what I have so far and we want to update the table. Thank you.
Join group table to updated table directly:
UPDATE outputtable O JOIN
(SELECT personID, COUNT(DISTINCT year) AS countYear
FROM outputtable GROUP BY personID) temp ON O.personID=temp.personID
SET O.N=temp.countYear

update with select result conditional takes too long [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
update A
set step1_response='step2',
step1_editor='step2'
where ch_idx in (select B.ch_idx
from B
where B.check_e_done_ct=B.check_e_tot_ct
AND B.check_w_tot_ct=B.check_w_done_ct);
The result of select inside the parentheses is about 4000 rows.
The table to be updated (A) is about 90000 rows.
the command above takes forever to complete.
how can i re-write this query to get result faster?
thank you!
UPDATE a
JOIN b USING (ch_idx)
SET a.step1_response='step2',
a.step1_editor='step2'
WHERE b.check_e_done_ct = b.check_e_tot_ct
AND b.check_w_tot_ct = b.check_w_done_ct;
or maybe
UPDATE a
JOIN ( SELECT ch_idx
FROM b
WHERE b.check_e_done_ct = b.check_e_tot_ct
AND b.check_w_tot_ct = b.check_w_done_ct ) bb USING (ch_idx)
SET a.step1_response='step2',
a.step1_editor='step2';

select two columns and run update query on them and do this in single query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i want to select two columns from database id and password
and want to use those two columns data in update query
example
select id , pass from table
second update query
update table set password2=password_get_from select_query where id=id_get_from_select_query
Try something like.
update table_one as A
inner join table_two AS B on (A.id = B.id)
set A.some_column = B.some_column,
A.another_column = B.another_column
where blah

MySQL select from two tables and combine results? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a question about MySQL: I want to list results from a table but gather additional information about these results from another table by a foreign key.
My table YTPrograms has a foreign key called Author which corresponds to the Id of a second table called YTUsers from which I want to add the username to my result from the YTPrograms query. I'm not sure how to do this without having to query (the users table) for each result.
Try this:
SELECT p.something, u.username FROM YTPrograms p, YTUsers u WHERE p.Author = u.Id

What is most Efficient SQL Query? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to retrieve all the 'events' of a user (given user_id) using his subscriptions.
I know this can be done using subquery but it is slow.
Please suggest the best approach to achieve it.
Here is the sqlfiddle link:
http://sqlfiddle.com/#!2/dd48e3
And here is the design image:
If u remove the where clause you will get the events corresponding to each user
select e.*,s.fname
from users s
join routine r ON (s.user_id = r.user_id)
join events e ON (e.r_id = r.r_id)
where s.user_id = ?
select * from events e left join subscriptions s on s.r_id = e.r_id where s.user_id = ?