I'm posting this question because I did manage to find a similar question , but they weren't using aliases.
I have two tables - I want to grab everything from table1
and just grab the user_name
and Team
from table2
.
My original query is grabbing everything from table2
SELECT *
FROM qabin.allqas t1
JOIN login.users t2
ON (t1.Submitter = t2.user_name)
WHERE t1.Status='Complete'
That's all well and good and works fine, but I would like to just get the user_name
and the Team
To make things more interesting, they are in different databases, though it hasn't been an issue.
One is in the qabin
database and the other is in the login
database.
I have tried:
SELECT
qabin.allqas.* AS t1,
login.users.Team,
login.users.user_name
JOIN login.users t2
ON (t1.Submitter = t2.user_name)
WHERE t1.Status='Complete'
I need the t1 and t2 aliases because they are used elsewhere for building a larger query string.
Thanks in advance!
Why not use a subquery?
SELECT *
FROM qabin.allqas t1
JOIN (SELECT user_name, Team FROM login.users) t2
ON (t1.Submitter = t2.user_name)
WHERE t1.Status='Complete'
You cant use one alias (t1) for a set of columns. I guess what you are looking for is something like:
SELECT t1.*, t2.team, t2.user_name
FROM qabin.allqas t1
JOIN login.users t2
ON (t1.Submitter = t2.user_name)
WHERE t1.Status='Complete'
I would recommend using the real column names from t1 instead of t1.*
Try This query :
SELECT t1.*, t2.user_name, t2.Team
FROM qabin.allqas t1
JOIN login.users t2
ON t1.Submitter 1= t2.user_name
WHERE t1.Status='Complete'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.