-2
$query = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC LIMIT 1";$result = $conn->query($query);

This query pulls the last one only and i can view in section 1

$query2 = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC";$result2 = $conn->query($query2);

This query pulls all data to view in section 2

What is the change i need in query2 so that it can pull all data except the last one?

3 Answers3

0

If, column id is primary key and auto-incremented.

$query2 = "SELECT id,subject,date,notice 
           FROM sam_notice 
           WHERE id < (SELECT MAX(id) FROM sam_notice)";
Nana Partykar
  • 10,175
  • 8
  • 43
  • 73
0

Try

SELECT id,subject,date,notice 
 FROM sam_notice
WHERE id != (SELECT MAX(id) FROM sam_notice
Always Sunny
  • 29,081
  • 6
  • 43
  • 74
0

Don't look for an SQL way. Instead simply skip the 1st row (it's the last one since you used DESC) when using the result. Something like this:

$query2 = "SELECT id,subject,date,notice from sam_notice ORDER BY id DESC";
$result2 = $conn->query($query2);
$begin = TRUE;
while ($row = <some fetch method on $result2, depending on your current API>) {
  if($begin) {
    $begin = false;
    continue;
  }
  // use other rows...
}
cFreed
  • 4,062
  • 1
  • 19
  • 33