Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Below is the SQL statement I wrote but I get an error that says "ORDER BY clause (RecordNumber) conflicts with DISTINCT" and the RecordNumber is generated Automaticaly in my database. What might be the problem???


SQL
sql = "SELECT DISTINCT  membersTable.StudentNumber, membersTable.Name,membersTable.Surname,StudentMarks.SubjectCode,StudentMarks.DPMark,StudentMarks.ExamMark "
           + "FROM StudentMarks, membersTable, SubjectTable WHERE membersTable.StudentNumber = StudentMarks.StudentNumber AND StudentMarks.SubjectCode = SubjectTable.SubjectCode Order By RecordNumber ASC";
Posted

Hi Anele.Ngqandu,

Small changes in your query

SQL
sql = "SELECT DISTINCT  membersTable.StudentNumber, membersTable.Name,membersTable.Surname,StudentMarks.SubjectCode,StudentMarks.DPMark,StudentMarks.ExamMark,tableName.RecordNumber  "
           + "FROM StudentMarks, membersTable, SubjectTable WHERE membersTable.StudentNumber = StudentMarks.StudentNumber AND StudentMarks.SubjectCode = SubjectTable.SubjectCode Order By RecordNumber ASC";


After got the output you can delete the column of RecordNumber.
Note: But in your query do not apply the distinct condition for multiple columns.

Cheers :)
 
Share this answer
 
Comments
Anele Ngqandu 6-Sep-10 9:40am    
Cool thnx
Because ORDER BY items must appear in the select list if SELECT DISTINCT is specified
 
Share this answer
 
v2
Comments
Anele Ngqandu 6-Sep-10 9:40am    
Cool stuf!! thanx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900