SQL - where did "rv" come from

I’m new to SQL (and programming). Can someone explain to me what “rv” stands for in this block of code? I’m guessing it’s a short hand for the table named recommended_values but no where did it rename the table to rv. It just seems to randomly appear in the code. This one of the learning module solutions I’m working on and I hate to move on b/c I have no idea how they came up with the short hand rv. Thank you!!!

active_patients.Name as Name, round(LDL) as LDL,
active_patients.Address As Address,
active_patients.Phone as Phone
(SELECT Borderline_High, High
FROM recommended_values
JOIN active_patients on
panels.patient_ID = active_patients.ID
HAVING LDL>= rv.Borderline_High


Hi @msphilomath,

See if this helps you out please: Tables Aliases

The short is, as the title to the other post suggests; a Table Alias. SQL doesn’t not like knowing where it’s getting it’s info from. So every object needs a name. This object is a derived table, and needs a name in order for SQL to reference it correctly.

1 Like

Am I the only one thinking this particular exercise was of a whole other level of complexity with respect to the SQL exercise done previously? It’s like they passed from basic SQL queries to nested commands and new concepts (like this table aliases) out of the blue.


Totally agree and totally confused by this project. Not sure what the point of having a project where you’re being asked to do things you’ve never done before and with no help other than to just give you the whole code.

Working on this same project, and fully agree that it was too much of a jump from previous lessons/exercises. What I’m not following is why my code returns different results from the suggested code - any help is appreciated

My code:

select active_patients.name as ‘Name’,
round(panels.ldl) as ‘LDL’,
active_patients.address as ‘Address’,
active_patients.phone as ‘Phone’
from panels, active_patients
where LDL >= ‘130’
group by name
order by LDL desc
limit 5;


|Alfredo Haggis|136.0|9 Roth Terrace|596-731-3727|
|Anastasia Bartolomieu|136.0|57 Fallview Street|326-441-6684|
|Antonella Horsell|136.0|19 Roth Road|380-427-0552|
|Ariel Gooday|136.0|2836 Harbort Drive|292-741-8754|
|Bari Arnely|136.0|860 Sycamore Way|692-377-4787|

their code is returning results w/ LDL of 199, why are mine cut off at 136? brand new to sql

I think you need to use the table connection, otherwise the data will be incomplete.

For those who are still struggling to understand how the rv alias is working, it is just an alternative to using WITH alias AS ().

So, this code:

is exactly the same as this:

WITH rv AS (
SELECT Borderline_High, High
FROM recommended_values
WHERE Lipid = ‘LDL’)
active_patients.Name AS ‘Name’,
round(panels.LDL) AS ‘LDL’,
active_patients.Address AS ‘Address’,
active_patients.Phone AS ‘Phone’
panels, rv

Why they decided to include that as the hint without explaining that it works this way is beyond me, but if you watch the video (made for a previous version of the exercise) it is completed using WITH AS.


I’ve just started to learn programming and SQL my first language so this project is a little strange. Feels like I’ve skipped some necessary info about how to do its tasks. T_T
Also there was nowhere to find out which type of patients I should use - active or inactive? So I did it in my way using everything I’ve learned in the lessons:

create table all_patients as
select * from active_patients
select * from inactive_patients;

with together as (
select * from all_patients
join panels
on panels.patient_ID = all_patients.ID)

select together.Name as ‘Name’,
when together.LDL >= recommended_values.High then ‘High’
when together.LDL >= recommended_values.Borderline_High then ‘Borderline High’
else ‘low’
end as ‘Level’,
together.LDL as ‘LDL’,
together.Address as ‘Address’,
together.Phone as ‘Phone’
from together, recommended_values
where recommended_values.Lipid = ‘LDL’ and
LDL > 129
order by 3 desc;


totally agree! I had to look all the time to the hints they give…you’re not the only one, uf