Dear all,
Am half way through my computer lab management project. to generate the timetable automatically i've written an algorithm. and for it to work i need an sql query that can :

table-> ttprofile:
id lab_name subject_name.

now i looked every where, is there a command to take the first five lab_name to another table inside am(column name),and the next 5 to pm(columnname).

the above was not that tricky, i want to compare "pm" values with am so that the Subject names are not the same.

am doing my first project , am really stuck with this for hours..

Yes, this is possible.

To select a range of rows, you use the LIMIT element.

E.G. SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15

"With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the MAXIMUM number of rows to return. The offset of the initial row is 0 (not 1)" - MySQL

To insert these rows into another table you use the INTO element.



Altogether you should have something like this:

SELECT lab_name INTO TBL(AM) FROM tbl LIMIT 0,5; //Gets first 5 
SELECT lab_name INTO TBL(PM) FROM tbl LIMIT 5,5; //Gets from record 6 to next 5

Hope that helps :)

Alternative methods & resources:

thanks , that really helped with the first problem.:)

the second part where it has to check whether:
table1> am:
id subject class_attending
0 oops it i
1 c++ it ii

table2> pm:
id subject class_attending
0 ds it i
1 os it iii

now my second question is,
i have to add the subjects of second column as a new column inside table one, such that no class_attending matches in a row.

Be a part of the DaniWeb community

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