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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:43:46+00:00 2026-06-16T01:43:46+00:00

Given a user name in a Drupal 7.17 database using PostgreSQL 8.4.13 I am

  • 0

Given a user name in a Drupal 7.17 database using PostgreSQL 8.4.13 I am trying to fetch user info (uid, city, gender, avatar) distributed over several tables.

The avatar (the f.filename below) is however optional – some users don’t have it.

For users, that do have avatars my query works well:

#  select
        u.uid,
        /* u.pass, */
        f.filename,
        g.field_gender_value,
        c.field_city_value
from
        drupal_users u,
        drupal_file_managed f,
        drupal_field_data_field_gender g,
        drupal_field_data_field_city c
where
        u.name='Alex' and
        u.picture=f.fid and
        g.entity_id=u.uid and
        c.entity_id=u.uid
;
 uid |         filename         | field_gender_value | field_city_value
-----+--------------------------+--------------------+------------------
   1 | picture-1-1312223092.jpg | Male               | Bochum
(1 row)

However for users, who don’t have avatar I get empty result.

When I omit the drupal_file_managed f table – it works again:

#  select
        u.uid,
        /* u.pass, */

        g.field_gender_value,
        c.field_city_value
from
        drupal_users u,

        drupal_field_data_field_gender g,
        drupal_field_data_field_city c
where
        u.name='mvp' and

        g.entity_id=u.uid and
        c.entity_id=u.uid
;
  uid  | field_gender_value | field_city_value
-------+--------------------+------------------
 18539 | Male               | Moscow
(1 row)

How could I modify my join statement to ensure that it always returns 1 row for valid users – regardless if they have avatar or not? The f.filename column can be null for the latter cases.

Do I want a left outer join here? (I’m afraid it will return several rows instead of 1).

  • 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-16T01:43:48+00:00Added an answer on June 16, 2026 at 1:43 am

    With COALESCE() you can even plug in a default value, if the filename appears to be missing:

    SELECT u.uid AS uid
            , COALESCE(f.filename, 'goatsex.jpg') AS filename
            , g.field_gender_value AS gender_value
            , c.field_city_value AS city_value
    FROM drupal_users u
    JOIN drupal_field_data_field_gender g ON g.entity_id=u.uid 
    JOIN drupal_field_data_field_city c ON c.entity_id=u.uid
    LEFT JOIN drupal_file_managed f ON u.picture=f.fid 
    WHERE u.name='Alex' 
            ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given table USER (name, city, age), what's the best way to get the user
I am trying to get the full name of a given user from active
Anyone know how to get a user's short user name, eg. johnsmith, given their
Given this XML file: <users blessed=phrogz alians> <user name=phrogz id=42 /> <user name=lachtok id=3
I'm developing a small application that, given a user name, it gets the user
Given, case class User(name: String, roles: List[String]) val users: List[User] = ... I'd like
I want to get the user name who has launched the given application. For
I need to validate a given Name field in the asp.net form. User Name:
I'm trying to set this up where the user gives username and password in-app,
I have a class called UserInfo that contains details about a given user. There

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.