4
Table: UserInfoTbl
=======================
| username  | type    |
=======================
| user0001  | premium |
| user0002  | premium |
| user0003  | normal  |
| user0004  | premium |
=======================

Table: UserPvTbl
========================
| username | fUsername |
========================
| user0003 | user0002  |
| user0002 | user0001  |
| user0003 | user0001  |
========================

How can I select all the information from UserInfoTbl where fUsername of UserPvTbl has username of user0003?

Edit: Meaning that I need to retrieve information of user0002 and user0001 from the UserInfoTbl

Edit2: Relationship between both tables : UserInfoTbl.username = UserPvTbl.username

3 Answers 3

8

DroidMatt can you clarify what the 2 tables relationship are

UserInfoTbl.username = UserPvTbl.fusername
or
UserInfoTbl.username = UserPvTbl.username

Vikram is right assuming the first. otherwise you want this.

SELECT *
FROM UserInfoTbl, UserPvTbl
WHERE UserPvTbl.username = UserInfoTbl.username
AND UserPvTbl.username = 'user0003'
Sign up to request clarification or add additional context in comments.

2 Comments

UserInfoTbl.username = UserPvTbl.username is the correct one. Sorry I forgot to clarify the relationship.
Note: Vikram just renamed/shortened the table names. UserInfoTbl = U and UserPvTbl = UP
1

Use like :

select * from UserInfoTbl inner join UserPvTbl on UserInfoTbl.username=UserPvTbl.fusename
where UserPvTbl.usename='user0003'

Comments

0
select U.*
from UserInfoTbl U
inner join UserPvTbl UP
on U.username  = UP.fusername  
where UP.username = 'user0003'

2 Comments

Hello Vikram. Do you mind to explain on U.* , UP and 'from UserInfoTbl U'? Im kinda lost here.
U is short name for UserInfoTbl, UP for UserPvTbl and U.* will return all the column of UserInfoTbl

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.