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

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

Related

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';

MYSQL delete all emails if email_address is in second table [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 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

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

Inserting data obtained via SELECT queries [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 8 years ago.
Improve this question
How can I do this correctly?
INSERT INTO tbl_task (`Assignedby`,`userID`)
SELECT ID FROM tbl_users WHERE UserName='$_GET[u]',
SELECT ID FROM tbl_users WHERE UserName='$_GET[at]'
Assuming you want to insert one row with two columns, I think you might want this:
INSERT INTO tbl_task(`Assignedby`, `userID`)
SELECT (SELECT ID FROM tbl_users WHERE UserName='$_GET[u]'),
(SELECT ID FROM tbl_users WHERE UserName='$_GET[at]');

How to get an attribute of parent of a table in sql stored procedure? [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 8 years ago.
Improve this question
I want to write a select stored procedure and in the where clause I want to check value of a field of the parent table of the curent table which I am performing the select query On , How can I acheive this ?
any helps would be appreciated
You'll nedd to JOIN those tables. Without knowing the tables definition, your query should look something like this:
SELECT C.* --- List the columns you want here
FROM ChildTable C
INNER JOIN ParentTable P
ON C.ParentID = P.ID --- something along this lines
WHERE P.SomeField = 1 --- put here your condition on the parent table