Skip to content
Advertisement

SQL query join tables data

I have 2 tables Users and TimeSheets, Timesheets table has column UserId which is users id form users table obviously ๐Ÿ™‚

Logic

And Iโ€™m trying to get all data of Timesheets table plus just name of user from users table but somehow it seems like my query is other way around!

Now I know this might be a simple query but I personally have no idea about SQL (my bad!)

Here is my query:

And here is screenshot of returned data:

one

As you can see I get my users names without any data being existed in timesheets table!

This view supposed to get timesheets table and then username of each row from users.

Update

Here is my timesheets table schema

And here is users table

Advertisement

Answer

It seems that you want an INNER join and since you are not doing any aggregation there is no need for GROUP BY:

By doing an INNER join you get results only when there is a match between 2 rows in the 2 tables.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement