Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Where Condition About Range Value

I have two tables like this,

create table tblCard(
Start_Id int,
End_Id int,
Card_Name varchar(100))

create table tblVisitor(
Card_Id int,
Visitor_Name varchar(150)
)

insert into tblCard values (1,50,'Engineer')
insert into tblCard values (51,100,'Helper')
insert into tblCard values (101,200,'Employeer')

insert into tblVisitor values (23,'PersonA')
insert into tblVisitor values (53,'PersonB')
insert into tblVisitor values (101,'PersonC')


select V.Card_Id,V.Visitor_Name,C.Card_Name from tblVisitor V join tblCard C on **??**

What should I syntax for question marked place

Firstly I think case when conditions one by one but maybe there is exists easier way Could you help me about this situation.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try this, is this your expected result.

SELECT V.Card_Id, V.Visitor_Name, C.Card_Name
FROM tblVisitor AS V
INNER JOIN tblCard AS C ON V.Card_Id BETWEEN C.Start_Id AND C.End_Id
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading