Newbie Question: How to implement example code?

Hi All,
I'm brand new to SQL but can usually pick up programming pretty easy so this is frustrating. When I see the example code for this solution, I'm not sure how to interpret it. Excuse my ignorance, please!!

When this code says to select "r", is that a dummy table name or is the user meant to insert the name of the table with the data in it? And is create_date something you leave in there, or do you define it elsewhere, or insert your own date? Is rev_id the id you want to group by?

Just simple, quick descriptions of what these terms are referring to would help me so much and would be greatly appreciated.
select r.* from review as r
inner join 
(
select rev_id,max(create_date) as max_dat
from review
group by rev_id
) as rev_max  on r.rev_id = rev_max.rev_id and r.create_date = rev_max.create_date

Open in new window

chaimberbellAsked:
Who is Participating?
 
natlozConnect With a Mentor Commented:
"r" now represents the table "review"

you could go...

select a.value, b.value
from tblApple a
inner join tblBanana b on pkFruitID = fkFruitID
where a.value = 'green' and b.value = 'yellow'

a = tblApple
b = tblBanana
0
 
natlozCommented:
select r.* from review as r

This statemet "from review as r" has aliased "r" as the new table name which can than be used in the query....
0
 
chaimberbellAuthor Commented:
Ah, thanks. That part makes more sense now.

What about the create_date part?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
natlozCommented:
create_date looks like it is simply a field in "review" that is being passed into the MAX function to gets the maximum value found.
0
 
natlozCommented:
Depending on what you are trying to combine will determine what you want to group by.
If there is only one create_date per review and you are looking for the max of create_date, I would probably group by create_date and remove rev_id from the query, since any field in a query that has an aggregate function (such as MAX) has to be in the group by statement.
0
 
chaimberbellAuthor Commented:
Thanks!
0
 
chaimberbellAuthor Commented:
I missed that those were the names of the fields. Thanks for clarifying! I'm gonna give it a try now :-).
0
All Courses

From novice to tech pro — start learning today.