[Ssh paging problem] during ssh development, mysql reports duplicatecolumn for help.

Source: Internet
Author: User
For ssh development, mysql is used for databases. ** _ When paging, you need to obtain the total data function totalCount, get totalPage, and get the code of totalCount (excluding the code such as binding parameters and checking input parameters): _ ** & quot; * ** retrieve the total number of records * protectedintgetTotalCount (Sessions, Stringsql) {construct the count query SQL & quot; SELECTCOUNT (1) FROM (& quot; + SQL + & quot ;) tmp & quot; Que paging mysqlduplicate column

For ssh development, mysql is used for databases.
When paging is performed, you need to obtain the total data function totalCount, get totalPage, and get the code of totalCount (excluding the code such as binding parameters and checking input parameters ):

/*** Get the total number of records */protected int getTotalCount (Session s, String SQL) {// Construct the count query SQL = "SELECT COUNT (1) FROM ("+ SQL +") tmp "; Query countQuery = s. createSQLQuery (SQL); // output result List countList = countQuery. list (); return (Integer) countList. get (0 );}

The above code reports "Duplicate column name 'xxxx'" in special circumstances, for example:
User table field: ** _ user_id _ **, login_name, passwd ,...
User_detail table field: user_detail_id,User_id, Address ,...
Query SQL (** _ code SQL1 _ **): select * from user u inner join user_detail ud on u. user_id = ud. user_id

The final SQL code for totalCount query (codenamed SQL2) is:
Select count (1) from (
Select * from user u inner join user_detail ud on u. user_id = ud. user_id
) Tmp
The execution reports an error because the user and user_detail tables both have the user_id field. the result of SQL1 contains the user_id field. when the tmp table is referenced in SQL2, a duplicate name error is reported.

I would like to ask the following questions:
1. if SQL 2 is executed in oracle, no error is reported. Is there a way to change the mysql settings so that no error is reported when SQL 2 is executed?
2. is there any other way to calculate totalCount?

Fresh Meat has been written by heroes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.