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 7819515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:58:58+00:00 2026-06-02T06:58:58+00:00

I’ve got to queries that are identical except that in the one query I

  • 0

I’ve got to queries that are “identical” except that in the one query I only retrieve one column from the table whereas in the other one I retrieve several columns from the same table. Otherwise everything is identical. For some reason, the order is not exactly the same in the results from the two queries. How can this be?

These are the two queries:

SELECT b.bruker_id, b.poeng_j + b.poeng_ss + b.poeng_u + b.poeng_n + b.poeng_s + b.poeng_f + b.poeng_v AS orderColumn
FROM brukere b
JOIN soknad s ON b.bruker_id = s.bruker_id
WHERE s.t_start_y =2013
AND s.t_start_s =0
AND YEAR( NOW( ) ) - b.aar >30
AND YEAR( NOW( ) ) - b.aar <40
ORDER BY orderColumn DESC 
LIMIT 10 ;

SELECT b.bruker_id, b.poeng_j + b.poeng_ss + b.poeng_u + b.poeng_n + b.poeng_s + b.poeng_f + b.poeng_v AS orderColumn, b.etternavn, b.fornavn, YEAR( NOW( ) ) - b.aar AS alder, b.poeng_j, b.poeng_ss, b.poeng_u, b.poeng_n, b.poeng_s, b.poeng_f, b.poeng_v, b.kjonn
FROM brukere b
JOIN soknad s ON b.bruker_id = s.bruker_id
WHERE s.t_start_y =2013
AND s.t_start_s =0
AND YEAR( NOW( ) ) - b.aar >30
AND YEAR( NOW( ) ) - b.aar <40
ORDER BY orderColumn DESC 
LIMIT 10 ;

The first query returns:

+-----------+-------------+
| bruker_id | orderColumn |
+-----------+-------------+
|        92 |          29 |
|       271 |          28 |
|       645 |          28 |
|       323 |          27 |
|       487 |          27 |
|        58 |          27 |
|        76 |          27 |
|       289 |          26 |
|       759 |          26 |
|       128 |          26 |
+-----------+-------------+

And the scond query returns:

+-----------+-------------+-----------+----------+-------+------------+------------------+------------------+-------------+-----------+-----------------+------------+-------+
| bruker_id | orderColumn | etternavn | fornavn  | alder | poeng_j | poeng_ss | poeng_u | poeng_n | poeng_s | poeng_f | poeng_v | kjonn |
+-----------+-------------+-----------+----------+-------+------------+------------------+------------------+-------------+-----------+-----------------+------------+-------+
|        92 |          29 | Tonheim   | Kine     |    33 |          4 |               16 |                3 |           0 |         0 |               6 |          0 |     1 |
|       645 |          28 | Saue      | Laila    |    36 |          8 |               16 |                0 |           0 |         0 |               4 |          0 |     1 |
|       271 |          28 | Grønnevik | Karl     |    38 |          8 |               16 |                0 |           0 |         0 |               4 |          0 |     0 |
|        76 |          27 | Tornes    | Kristina |    39 |          5 |               16 |                0 |           0 |         0 |               6 |          0 |     1 |
|       487 |          27 | Smestad   | Tonje    |    34 |          8 |               16 |                0 |           0 |         0 |               0 |          3 |     1 |
|        58 |          27 | Torjussen | Linn     |    35 |          8 |               16 |                0 |           0 |         0 |               0 |          3 |     1 |
|       323 |          27 | Gillebo   | Tore     |    31 |          5 |               16 |                0 |           0 |         0 |               6 |          0 |     0 |
|       759 |          26 | Sætren    | Grete    |    36 |          4 |               16 |                0 |           0 |         0 |               6 |          0 |     1 |
|       289 |          26 | Gjersøe   | Torbjørn |    37 |          4 |               16 |                0 |           0 |         0 |               6 |          0 |     0 |
|       339 |          26 | Gjøen     | Fredrik  |    34 |          4 |               16 |                0 |           0 |         0 |               6 |          0 |     0 |
+-----------+-------------+-----------+----------+-------+------------+------------------+------------------+-------------+-----------+-----------------+------------+-------+

As you can see, the order is not the same…

  • 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-06-02T06:59:00+00:00Added an answer on June 2, 2026 at 6:59 am

    If you add a column to each SELECT first

    b.poeng_j + b.poeng_ss + b.poeng_u + b.poeng_n + b.poeng_s + b.poeng_f + b.poeng_v AS orderColumn
    

    Then change the queries to be ORDER BY orderColumn

    You will then be able to see clearly what it is ordering by. You will probably then see that some of the rows have the same value in orderColumn, and so the ordering may not be consistent without having a second ORDER BY criteria, i.e. ORDER BY orderColumn, bruker_id

    Using your second query I would end up with

    SELECT 
        b.bruker_id, 
        b.etternavn, 
        b.fornavn, 
        YEAR( NOW( ) ) - b.aar AS alder, 
        b.poeng_j, b.poeng_ss, 
        b.poeng_u, 
        b.poeng_n, b.poeng_s, 
        b.poeng_f, 
        b.poeng_v, 
        b.kjonn,
        (b.poeng_j + b.poeng_ss + b.poeng_u + b.poeng_n + b.poeng_s + b.poeng_f + b.poeng_v) AS orderColumn
    FROM brukere b
    JOIN soknad s ON b.bruker_id = s.bruker_id
    WHERE s.t_start_y =2013
        AND s.t_start_s =0
        AND YEAR( NOW( ) ) - b.aar >30
        AND YEAR( NOW( ) ) - b.aar <40
    ORDER BY orderColumn DESC, b.bruker_id ASC 
    LIMIT 10 ;
    

    In your sample data, bruker_id 645 and 271 both would have an orderColumn value of 28.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

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.