I'm wondering what is the most effective(fast and less work for database) way to retrieve data. I have 2 tables:
users
ID | NAME
1 | John
2 | Mike
3 | Jack
data
USER_ID | DATA
2 | some_data_1
3 | some_data_2
I need to get value by user name and as i understand i have two options:
select id from users where name ='some_name'and then select fromdatatable by id.
or
select id from users join data on users.id = data.user_id where user.name = 'some_name'
Also, i guess it's important to note: those are example of real tables with thousands of rows and few more columns, there is an index on user_id column in data table, I'm using jdbc driver under and it's a network call, and it's postgreSQL if it matters.
upd. Also, any links to researches or any kind of papers/docs/speeches would be very interesting to read