SQL query join or subquery [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 2 years ago.
Improve this question
[![table named teams and Matches ][2]][2]I have 2 tables
[2]: https://i.stack.imgur.com/7v4nT.png**strong text**
I need data from these 2 tables in such a ways that a new table is formed with the following data
mid, result, date, team1id, team2id from matches table on the basis of tourid=6 and from table of team i need to show the Tname as team1 and Tname as team2.

Sounds like you need a join:
select matches.*,t1.Tname as team1,t2.Tname as team2 from matches
join team t1 on t1.Teamid=matches.team1id
join team t2 on t2.Teamid=matches.team2id
where tourid=6

Related

sql - mysql - tables [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 yesterday.
Improve this question
I need to collect the name and total order of customers who had an order of more than 56000. there are three tables, customers, orders, and orderdetails.
This is the output that I need:
this is the code that im trying:
select a.customername, sum(c.priceeach*c.quantityordered) as "ORDERTOTAL"
from customers a
join orders b on b.customernumber = a.customernumber
join orderdetails c on c.ordernumber = b.ordernumber
having sum(c.priceeach*c.quantityordered) > 58000
group by a.customername;
but it is giving me 76 rows.
when I only try with the table order details i can get exact 7 rows but the table orderdetails doesnt contain customername, I can't undrestand where am I doing it wrong.

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

mySQL select every record that does not exist in another 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
I have 3 tables:
users (id_user)
achievements (id_achievement)
user_achievements (id_user, id_achievement)
I need help selecting every achievement that a user has not yet completed.
Consider a cross join that generates all combinations of users and achievements, and a not exists condition with a correlated subquery to filter out those that were completed already:
select u.id_user, a.id_achievement
from users u
cross join achievements a
where not exists (
select 1
from user_achievements ua
where ua.id_user = u.id_user and ua.id_achievement = a.id_achievement
)

Show in the tables, only the last statues [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
I have a simple entry in the oracle, there are 3 columns, date, API name and status. I want that in the answer I had not all history, and only the last on each of Names of API (only 7). I will be grateful for your help. I know that asked of the very difficult but I'm just new to oracle.
select l.log_date,l.job_name,l.status from user_scheduler_job_log l
could be you want the related status for name and last log_date
select u.job_name, u.status, t.max_date
from user_scheduler_job_log u
INNER JOIN(
select MAX(l.log_date) max_date, l.job_name
from user_scheduler_job_log l
GROUP BY l.job_name
) t on t.max_date = u.log_date
AND t.job_name = u.job_name

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