I have a table: student_marks
marks ----- 44 55 64 98 76
Expected output:
serial_number|marks -------------------- 1 | 44 2 | 55 3 | 64 4 | 98 5 | 76
Using mysql user defined variables, it could be done using query:
set @a:=0;select @a:=@a+1 serial_number, marks from student_marks;
Is there any way to achieve this in msyql without using user defined variables?
To generate serial number i.e. row count in MySQL query, use the following syntax. mysql> select *from tblStudentInformation; The following is the output.
Then add a textbox control in this subform and set its Control Source to =SerialNumber([Form]) . That would fulfill all your needs. Remark: If you delete a record in the subform you would have to refresh the subform to update the serial numbering.
SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE . SERIAL DEFAULT VALUE in the definition of an integer column is an alias for NOT NULL AUTO_INCREMENT UNIQUE .
Query Profiler, built into dbForge Studio for MySQL, is the best query optimization tool to tune MySQL queries and investigate query performance issues in an efficient and fast way. It helps build up a picture of how the queries are run to access data and what operations impact your application.
Based on your reasons for not wanting to use user defined variables as wanting to avoid having 2 queries, one for inializing and one to use it you could use the following:
SELECT @a:=@a+1 serial_number, marks FROM student_marks, (SELECT @a:= 0) AS a;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With