1

Is it possible to use select * for only one table when using a join statement?

Let's say these are the following tables;

B
userID
username

A
userID
entry 
....just pretend there are more columns for the sake of this example

What is the correct way to look up the username from table B?

select B.username, * from A
LEFT JOIN B on B.userID = A.userID
where A.entry = "XXXXX"

Or do I have to list out everything I want to select such as:

select B.username, A.userID, A.entry from A
left Join.....
2
  • What happens when you try it? You'd have had an answer a lot faster than asking here, and you might learn something useful in the process. :) Commented Apr 24, 2012 at 23:48
  • Be sure to accept an answer for this question :) Commented Apr 25, 2012 at 0:00

2 Answers 2

3

You can use [table name].* to select all fields from one of the tables. For example, to select all fields from table B use:

 SELECT B.*, username FROM A
 LEFT JOIN B on B.userID = A.userID
 WHERE A.entry = "XXXXX"

edit - selected column username from A

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, yours worked. I had to add username and then it worked perfectly.
1

SELECT A.* FROM ... where A is the table you want to select from.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.