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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:22:41+00:00 2026-05-29T15:22:41+00:00

TABLE users_community_relations list_id int user_id int dest_user_id int 1 10 20 2 10 24

  • 0
TABLE users_community_relations

list_id int user_id int dest_user_id int
  1           10            20
  2           10            24
  3           10            33
  4           11            10

TABLE users_avatar

avatar_id int user_id int  webavatar_thumbnail
    1            10            test.jpg
    2            10            test2.jpg
    3            20            test2.jpg
    4            20            test11.jpg

TABLE users

user_id int  nick varchar
  10         kaka
  20         caca
  24         dada
  33         roro

I need to query this three tables there is the logic, table users_community_relations wheen i put user_id = 10 for example i get results from same table column dest_user_id 20,24,33 each number represent user_id in next two tables, i would need to get all data from next two tables accordingly to 20,24,33 numbers from dest_user_id column. Sometimes table users_avatar does not hold any avatar for user in that case string from this table could be empty. Sometimes it holds more than two rows, in that case i would need to get only first one but ordered with avatar_id DESC users_avatar table.

  • 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-29T15:22:42+00:00Added an answer on May 29, 2026 at 3:22 pm

    This should work:

    SELECT ucr.*, u.*, ua1.*
    FROM users_community_relations ucr
    LEFT JOIN users u
      ON u.user_id = ucr.user_id
    LEFT JOIN users_avatar ua1
      ON ua1.user_id = u.user_id
    LEFT JOIN users_avatar ua2
      ON ua2.user_id = u.user_id AND ua2.avatar_id > ua1.avatar_id
    WHERE ua2.avatar_id IS NULL
    

    It uses joins to ensure we only return the user_avatar row with the highest avatar_id or NULL if there is no avatar.

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

Sidebar

Related Questions

I have a table [Users] with the following columns: INT SmallDateTime Bit Bit [UserId],
I have a table users which has a primary key userid and a datetime
I have a user table 'users' that has fields like: id first_name last_name ...
I have a table Users and a table Items In the Items table, I
Design of SQL Table Users: Columns: ID(Primary Key), Name, Age, Zip. I am displaying
I have a table users with primary index userId . Currently, each user has
I have dbml with single table users i want add partial class for User
When registering my first user in table 'users' the id is the same value
How could i create a trigger that at any insertion on my table [users]
I have 2 tables (Users, Wall). The UserID in the Wall table is 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.