Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:01:59+00:00 2026-05-25T17:01:59+00:00

I have a form to edit mysql table columns. There are links that I

  • 0

I have a form to edit mysql table columns. There are links that I can click onto and load Previous, Next, First or Last row. I can order the columns (max. four columns to be ordered). So when I press Prev. or Next, the columns have to be ordered first and then I can get the result. I use mysql View for this. It is important to know that columns are text, but id is number. I usually order by first text columns and then by id.

And here is my query that worked to me for single column order.

Previous:

  SELECT  x.* 
    FROM  test_view x, test_view y 
   WHERE   y.`id` = 13 
           AND ( x.`cat` < y.`cat` OR ( x.`cat` = y.`cat` AND x.`id` < y.`id`)) 
ORDER BY  x.`cat`, x.`id` DESC   
   LIMIT  0,1

Next:

  SELECT  x.* 
    FROM  test_view x, test_view y 
   WHERE  y.`id` = 13 
          AND (x.`cat` > y.`cat` OR (x.`cat` = y.`cat` AND x.`id` > y.`id`)) 
ORDER BY  x.`cat`, x.`id` ASC   
   LIMIT  0,1

I tried to expand this to find multiple columns as this:

SELECT x . *
FROM ukazka_view x, ukazka_view y
WHERE y.`id` =1
AND (
x.`cat` < y.`cat`
OR (
x.`cat` = y.`cat`
AND x.`id` < y.`id`
)
)
AND (
x.`typ` < y.`typ`
OR (
x.`typ` = y.`typ`
AND x.`id` < y.`id`
)
)
AND (
x.`diff` < y.`diff`
OR (
x.`diff` = y.`diff`
AND x.`id` < y.`id`
)
)
ORDER BY x.`cat` DESC , x.`typ` DESC , x.`diff` DESC , x.`id` DESC
LIMIT 0 , 1

But this has no results.

Edited:

I tried to write a query for case that actual row id is 1.

    SELECT x.* FROM  ukazka_view x INNER JOIN ukazka_view y ON  
( x.`cat` < y.`cat` OR 
( x.`cat` = y.`cat` AND x.`id` < y.`id`) OR
( x.`cat` = y.`cat` AND y.`id` = 1 AND x.`id` > y.`id`))

AND
( x.typ < y.typ OR
( x.typ = y.typ AND x.id < y.id) OR
( x.typ = y.typ AND y.id = 1 AND x.id > y.id))
AND
( x.diff < y.diff OR
( x.diff = y.diff AND x.id < y.id) OR
( x.diff = y.diff AND y.id = 1 AND x.id > y.id))
WHERE y.id = 1
ORDER BY x.cat DESC, x.typ DESC, x.diff DESC, x.id DESC LIMIT 0,1

This looks for previous row. Behavior is a little bit strange but works. So when I go to last value, I got id=1. Then When I press Previous (this query) it gets to id=82, when I press again Previous id=81 and so on till I got id=2. I cannot get to id=1 only when I press/select Last.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:01:59+00:00Added an answer on May 25, 2026 at 5:01 pm
    SELECT x.*
    FROM ukazka_view x
    INNER JOIN ukazka_view y 
      ON  (x.cat  < y.cat  OR (x.cat  = y.cat  AND x.id < y.id)) 
      AND (x.typ  < y.typ  OR (x.typ  = y.typ  AND x.id < y.id))  
      AND (x.diff < y.diff OR (x.diff = y.diff AND x.id < y.id))
    WHERE y.id = 1
    ORDER BY x.cat DESC , x.typ DESC , x.diff DESC , x.id DESC
    LIMIT 1 OFFSET 0
    

    The problem I see with this query is that an id cannot be smaller than 1.
    So x.id < y.id will always be false.
    This leaves only

    ....
      ON  (x.cat  < y.cat)
      AND (x.typ  < y.typ)
      AND (x.diff < y.diff)
    

    As a join criterion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function to edit all fields that come from the form and
I have an HTML/XML table generated by AJAX that displays limited columns of a
I have written a simple mysql search form that searches between two dates. This
How can I edit a certain data entry in MySQL? for example I have
I have a table form which contains a part where the rows can be
I have a form on a page where the user has inputs to edit
I have form area in my view. If I click button A , I
I have form that displays several keywords (standard set of choice lists that changes
I have form with 1 button. when you click on the button 3 others
I have form where user submits field. Field can have letters, numbers, and punctuation.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.