4 Replies - 397 Views - Last Post: 04 May 2017 - 11:19 PM

#1 rkmalbacias  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-May 17

Quering Distinct Data

Posted 04 May 2017 - 05:23 PM

Good day, I have this table of mine. Actually, it is a grade sheet table. My goal is to let student view their grade on a kiosk. Below is how my table grade sheet looks:
 -----------------------------
| subject_code | subject_name |
 -----------------------------
| 100          | English      |
| 101          | Math         |
| 105          | Science      |
| 110          | Computer     |
 -----------------------------
 ____________________________________________
gs_index | grade | subject_code | student_id |
---------------------------------------------
 1       | 1.0   | 100          | 12-12345   |
 2       | 2.0   | 100          | 12-12345   |
 3       | 3.0   | 101          | 12-12345   | 
 4       | 2.5   | 105          | 12-12345   |
 5       | 3.0   | 110          | 12-12345   |
---------------------------------------------


How dow i query grade sheet that it will only view the "2.0" grade with "100" subject_code"? I have tried Distinct or Group By. But still it does not work. Also, the reason that it has 1.0 and 2.0 grade with 100 subject code is that, everytime an instructor updated the grade, instead of update, I inserted the updated one. The last entry, would remain for tracing purposes.

This post has been edited by modi123_1: 04 May 2017 - 06:09 PM
Reason for edit:: Added code tags to the ascii table


Is This A Good Question/Topic? 0
  • +

Replies To: Quering Distinct Data

#2 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2329
  • View blog
  • Posts: 9,356
  • Joined: 03-December 12

Re: Quering Distinct Data

Posted 04 May 2017 - 06:10 PM

Sounds like homework more than using it in a kiosk. Why would you want to only view 2.0 grades if this was not homework?


What queries have you attempted?
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,477
  • Joined: 12-June 08

Re: Quering Distinct Data

Posted 04 May 2017 - 06:11 PM

So you want the max 'gs_index' of a given 'subject code'?
Was This Post Helpful? 0
  • +
  • -

#4 rkmalbacias  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-May 17

Re: Quering Distinct Data

Posted 04 May 2017 - 08:23 PM

This is my code:

$dbQ = $sdb->selectQry('Select DISTINCT s_index From dbo.G_SHEET_FINAL Where user_index_ = 8886');

	echo '<table>';
	echo '<tr>';
	echo '<td>Subject Code</td>';
	echo '<td>Subject Name</td>';
	echo '<td>Grade</td>';
	echo '<td>Year</td>';
	echo '<td>Semester</td>';
	echo '</tr>';
	
	for ($i=0; $row = $dbQ->fetch(); $i++) {
		$subjectCode = $row['s_index'];

		$sdbc = new saFunction();
		//$dbQ2 = $sdbc->sRowQry('Select GRADE, user_index_ From dbo.G_SHEET_FINAL Where s_index = ? and user_index_ = 10572', [$subjectCode]);
		$dbQ2 = $sdbc->sRowQry('Select * From view_studCur Where s_index = ? and user_index_ = 8886', [$subjectCode]);
			for ($x=0; $row = $dbQ2->fetch(); $x++) {
				$subcode = $row['SUB_CODE'];
				$subName = $row['SUB_NAME'];
				$studGrade = $row['GRADE'];
				$currentYear = $row['CURRENT_YEAR_LEVEL'];
				$currentSem = $row['CURRENT_SEMESTER'];
			}

		echo '<tr>';
		echo '<td>'. $subcode .'</td>';
		echo '<td>'. $subName .'</td>';
		echo '<td>'. $studGrade .'</td>';
		echo '<td>'. $currentYear .'</td>';
		echo '<td>'. $currentSem .'</td>';
		echo '</tr>';
	}

	
	echo '</table>';


so far, it shows the data i want but I can't order them by year level, current semester, and subjectCode
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,569
  • Joined: 12-December 12

Re: Quering Distinct Data

Posted 04 May 2017 - 11:19 PM

They are not ordered because you have no ORDER BY clause.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1