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

  • Home
  • SEARCH
  • 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 7870735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:42:26+00:00 2026-06-03T01:42:26+00:00

In PostgreSQL 8.4 I have a join always returning 3 rows (they represent 3

  • 0

In PostgreSQL 8.4 I have a join always returning 3 rows (they represent 3 players playing the game round rid) –

# SELECT r.rid, c2.pos, c2.money, c2.last_ip, c2.quit,
u.id, u.first_name
FROM pref_rounds r
JOIN pref_cards c1 USING (rid)
JOIN pref_cards c2 USING (rid)
JOIN pref_users u ON u.id = c2.id
WHERE c1.id = 'OK336197153288';
  rid   | pos | money |     last_ip     | quit |          id           | first_name
--------+-----+-------+-----------------+------+-----------------------+------------
 165684 |   0 |    14 | 77.91.175.242   | f    | OK336197153288        | Елена
 165684 |   1 |    -2 | 195.177.124.218 | f    | OK3982469933          | Константин
 165684 |   2 |   -14 | 92.243.183.44   | f    | MR438331292705069453  | Дмитрий

 165711 |   2 |    10 | 77.91.175.242   | f    | OK336197153288        | Елена
 165711 |   0 |    -2 | 195.177.124.218 | f    | OK3982469933          | Константин
 165711 |   1 |    -6 | 92.243.183.44   | f    | MR438331292705069453  | Дмитрий

 165764 |   1 |    13 | 77.91.175.242   | f    | OK336197153288        | Елена
 165764 |   2 |   -17 | 195.177.124.218 | f    | OK3982469933          | Константин
 165764 |   0 |     3 | 92.243.183.44   | f    | MR438331292705069453  | Дмитрий

Unfortunately they are not sorted by the pos (the 2nd column which is a position at a playing table).

Is there please a way in SQL to sort the above sets of 3 rows so that they always have the pos: 0 1 2 then again 0 1 2?

Or do I have to do it in my PHP script?

  • 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-03T01:42:27+00:00Added an answer on June 3, 2026 at 1:42 am

    Use the following sql query. It will give you the required result.

    # SELECT r.rid, c2.pos, c2.money, c2.last_ip, c2.quit,
    u.id, u.first_name
    FROM pref_rounds r
    JOIN pref_cards c1 USING (rid)
    JOIN pref_cards c2 USING (rid)
    JOIN pref_users u ON u.id = c2.id
    WHERE c1.id = 'OK336197153288'
    Order by r.rid asc, c2.pos asc
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have postgresql (in perlu) function getTravelTime(integer, timestamp), which tries to select data for
I have a query on a PostgreSQL system returning a boolean: my $sth =
I have a PostgreSQL database with two tables named user and group. They have
I have this code: SELECT tblschemeprojectpaymentgateway.paymentgatewayid, paymentgatewayname FROM + tblschemeprojectpaymentgateway INNER JOIN tblpaymentgateway ON
I have a couple of million rows in a postgresql table. I have up
I have the following query: SELECT table_a.field1, table_b.field1 FROM table_a, table_c LEFT JOIN table_b
In PostgreSQL 8.4.8 database I have 2 tables: noreset and track . They have
I'm trying to save scores of card game matches (always with 3 players) into
I have one query written in postgresql select components.* from sg_paycomponents components left outer
I'd need advice on following situation with Oracle/PostgreSQL: I have a db table with

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.