I have the following table structure in MySQL for which I have to write code
id Docid deptid
-------------------
1 Doc1 dept1
2 Doc2 dept1
3 Doc3 dept2
4 Doc4 dept2
5 Doc5 dept2
I have to write a query to get Docid
in a sequential manner for the above MySQL structure in such a way that when client approach dept1
, which has 2 Docid
s – Doc1
and Doc2
. When a client approach dept1
for the first time it should direct him to Doc1
first and then to Doc2
, and if he again wants to approach dept1
for more Docs then code again redirect it to Doc1
and vice versa.
The same should happen for dept2
, which has 3 Docid
s – Doc3
, Doc4
and Doc5
. If the client approaches dept2
for the first time, then MySQL should direct it to Doc3
first, then to Doc4
and last to Doc5
. If the client has approached all the Docs in dept2
, he should be directed again to Doc3
and the whole cycle goes again whenever client approaches dept2
.
I am not getting how to write a query or restructure my table columns so that I can get next Docid
each and every time when I execute select query by filtering department wise.
Please guide me to restructure and write MySQL query for this case.
Thank you for all your valuable suggestions.