I have three tables
1.course(c_id(pk),c_name,sem_no);
2.student(s_id(pk),s_name,user_name,password);
3.student_info(s_id(fk),c_id(fk));

i have logged in the student..
den i run this query

select distinct sem_no from course,student_info where course.c_id=student_info.c_id and s_id='0001' order by sem_no;

it shows all the semster he passed inclueding the running semster..

now i want to show the last value of sem_no coloumn as his current semster..
how can i grab the last value of the sem_no???

SELECT MAX(COURSE.SEM_NO) FROM COURSE, STUDENT_INFO
WHERE COURSE.C_ID=STUDENT_INFO.C_ID
AND STUDENT_INFO.S_ID='0001';

You can try the below SQL Query

select top 1 sem_no from course, student_info
where course.c_id=student_info.c_id
and student_info.s_id='0001';
order by sem_no desc

have a good day :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.