![]() ![]() It has since been at least a few years and I am still happy with it. These pages should get updated by me once a month.Īs of early 2016 I have migrated my Internet-connected computers from Microsoft Windows 7 over to the free Linux Mint operating system. I am not affiliated with TCM.Īny ideas just PM me on the forums Here or Here Here we used date and time field dt ( of both tables ) to display records in order of data and time.This site is comprised of a series of reports which present my personal findings from the old TCM schedule data, in order to have as complete a picture as possible of their broadcast history. Read More on Union All SELECT dt, topic_id,userid Our order by query should collect data based on recent posts ( it can be topic or reply ) by comparing the posting date and time. We need to display top 10 recent posts by taking data from title and reply table. Each record stores date and time of post. One is storing topic with titles and other table is storing topic replies. In a discussion forum, members create a Topics ( with title ) and other or same member post reply to this topic. Order by two fields of two different tables How to give the option to the user to change the record display order ? SELECT * FROM `student` ORDER BY CAST(diff as unsigned) DESC We need to change the column value by using CAST and then use order by This is listed based on the first char of diff column. SELECT * FROM `student` order by diff desc While listing in order by any VARCHAR or string column having number, we need to convert them to number by using CAST and then use order by query.Ĭreate one more column diff, VARCHAR ( 3 ) then update it by using this query Only the query part is required to be changed. You can read more on SQL SELECT query to see how this query can be used in PHP Script to display records. SELECT * FROM student ORDER BY mark DESC, name DESC How to use in PHP Script If you want listing should be from highest mark to lowest mark then query should be SELECT * FROM student ORDER BY mark, name DESC If you want to reverse the order of Names you can change the query like this So the list will display Bigy above Giff Tow though both of them got equal mark ( say 88 ) When there are more than one student got the same mark ( say 88 ) then the names of them will be listed alphabetically. This will list on ascending order of mark. ![]() ![]() SELECT * FROM student ORDER BY mark, name We can display list of students based on their mark and based on their name. SELECT * FROM `student` ORDER BY class desc Order by more than one column of a table We have to add desc to the ORDER BY clause. Reverse the order by specifying in our sql command to change the order toĭescending that is from Z to A. Here the records are returned in the order by class from A to Z. SELECT * FROM `student` ORDER BY class id Here is the command to display the records in the order of class Read how Order by command is used to display highest 3 records of student table order by on a varchar field SELECT * FROM `student` ORDER BY class desc, mark desc id Will give a highly use full way by displaying all the records in order of class Here is the code toĭisplay the records in the order of class and then in the order of marks. To display the records in order of mark in aĬlass, we have to use to field names in the order by clause. Here the total mark will be displayed in the order of highest to lowest andĬlass will not be considered. SELECT * FROM `student` ORDER BY mark desc Here is the command to display the records in descending order ( from highest to Please note that by default all order by commands are in ascending order only. Lowest mark to highest mark by using the ASC command ( ascending command ) We can apply this to our numeric field mark to display the list in order of Order by MySQL query to display rows based on order of columns ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |