-3

I have two mysql tables.

UserInformation

UserInformation

and

referencelog

enter image description here

Now, most of the columns are not of interest. This is what I am trying to do:

  1. Get the unique "created_by_user_name" from referencelog for a given level id. I am able to do it by following query, which returns 3 unique user_name.

SELECT DISTINCT log.created_by_user_name FROM ReferenceScreenResultLog log WHERE level="1"

but I want to some how join this with UserInformation table, so I get the rows from UserInformation. As in I want the three rows from UserInformation table corresponding to these 3 unique user names I get from above query. The columne user_name in UserInformation table is connected with created_by_user_name column in referencelog table.

user1631306
  • 4,350
  • 8
  • 39
  • 74
  • 2
    Right so now you have all the information you need. Just add the JOIN and then you can use the userinformation columns – RiggsFolly Sep 08 '21 at 14:27
  • I know, but thats where I am struggling, Not comfortable with mysql much – user1631306 Sep 08 '21 at 14:28
  • Thats why some kind sole spent hours ne Days writing a manual and someone else spent another few days writing tutorials and putting them on the internet for you to use. Once you have attempted to write some code, if it does not work, then bring it here and ask for help, – RiggsFolly Sep 08 '21 at 14:33
  • I am sorry but, I did attempt to write SQL query to find the distinct username from one table. I mentioned it in the question. Did you see that? – user1631306 Sep 08 '21 at 14:39
  • Please provide sample data if possible – Rahul Biswas Sep 08 '21 at 14:40

1 Answers1

1

assuming that the two table are joined by usr.id = log.created_by
the you could use a join this way

SELECT DISTINCT usr.first_name, log.created_by_user_name 
FROM ReferenceScreenResultLog log 
INNER JOIN UserInformation usr on usr.id = log.created_by 
WHERE level="1"

or for all usr row content

SELECT DISTINCT usr.*, log.created_by_user_name 
FROM ReferenceScreenResultLog log 
INNER JOIN UserInformation usr on usr.id = log.created_by 
WHERE level="1"
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107