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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:38:14+00:00 2026-06-08T22:38:14+00:00

I have two tables drivers and drivers_names . What I want is for every

  • 0

I have two tables drivers and drivers_names. What I want is for every driver I select from the first table to have a random name from the second, but what I get is one name for all drivers in the result. Yes, it is different every time but is one for all. Here is my query, I’m using postgresql.

SELECT
    drivers.driver_id AS drivers_driver_id,
    (
        SELECT
            drivers_names.name_en
        FROM
            drivers_names
        ORDER BY random() LIMIT 1
    ) AS driver_name
FROM
    drivers

Result:

11  Denis
13  Denis
7   Denis

Tables structure.

drivers

+--------------+
| column_name  |
+--------------+
| driver_id    |
| property_1   |
| property_2   |
| property_3   |
+--------------+

drivers_names

+-------------+
| column_name |
+-------------+
| name_id     |
| name_en     |
+-------------+
  • 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-08T22:38:15+00:00Added an answer on June 8, 2026 at 10:38 pm

    Postgres probably evaluates the subselect only once because technically there’s no reason to evaluate it for every row.
    You could force it by referencing a column from the drivers table into the subselect, like this:

    SELECT
        drivers.driver_id AS drivers_driver_id,
        (
            SELECT
                drivers_names.name_en
            FROM
                drivers_names
            ORDER BY random()+drivers.driver_id LIMIT 1
        ) AS driver_name
    FROM
        drivers
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: DRIVER(Driver_Id,First name,Last name,...); PARTICIPANT IN CAR ACCIDENT(Participant_Id,Driver_Id-foreign key,responsibility-yes or no,...).
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
If I have two tables; Drivers keyed by DriverId and Trips with foreign keys
I have two tables Team_DATA and Driver_PROFILE_DATA in an SQL database. For every driver_profile
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables, a user table and a application table: User id username
using mysql and php, I have two tables, I'm french so the table names
I have this managed bean which takes two values from database's table import java.io.Serializable;
I have two tables, like this: master --------- empcode INT PRIMARY KEY name VARCHAR

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.