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..

Recommended Answers

All 2 Replies

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

http://dev.mysql.com/doc/refman/5.5/en/select.html

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

E.G. INTO TABLE (COLUMN)

-http://stackoverflow.com/questions/6194037/mysql-insert-without-having-to-specify-every-non-default-field-1067-invalid

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:

http://www.ntchosting.com/mysql/insert-data-into-table.html
http://dev.mysql.com/doc/refman/5.0/en/select-into.html

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.