user1274820 user1274820 - 6 months ago 9
PHP Question

Mysql Select All from one table, and some from another table Using Aliases

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!

Answer

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