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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:07:44+00:00 2026-05-18T08:07:44+00:00

I need to select a row only from two corresponding tables, for instance, member

  • 0

I need to select a row only from two corresponding tables, for instance,

member table,

member_id   member_name
1           xxx
2           yyy

profile_picture table

image_id   member_id   image_approved
1          1           no
2          1           no
3          1           yes

I want to select one row from member table each time and one approved image from profile_picture. I am using left join but it doesn’t work right as it duplicates the selected member when this member has more than 1 uploaded images. the tricky part is I want to select the image which has been approved only and it is always one picture will be approved.

SELECT *
    FROM member 

    LEFT JOIN profile_picture 
    ON profile_picture.member_id = member.member_id

    WHERE member.member_id = '1'

I would like to get this as a output,

member_id   member_name image_id image_approved
1           xxx         3        yes

is it possible?

thanks.

edit:

thanks guys for the suggestions. many of you have suggested using AND – for instance, AND profile_picture.image_approved = ‘yes’

it works only when the image is present. but if the image is absent, there is nothing in the output even though it should output like this below if the image is absent.

member_id   member_name image_id image_approved
1           xxx         null      null

thanks again!

  • 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-18T08:07:44+00:00Added an answer on May 18, 2026 at 8:07 am
    select
      *
    from
      member m
      left join profile_picture p on p.member_id = m.member_id
    where
      m.member_id = '1'
      and (p.image_approved is null or p.image_approved = 'yes')
    

    image_approved isn’t part of the join condition, so I don’t put that in the join clause. It’s rather part of the row selection condition, so it goes in where. Thinking about what you want, you either want nothing in profile_picture, or the approved row. So, conditions.

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

Sidebar

Related Questions

I need to select only 20 records from the table and than add pagination
I'm trying to preform a SELECT query that grabs data from two tables only
I need to select all from table1 where active=1 and replace t1cid,t2cid,L1cid,L2cid---L10cid with corresponding
I have two product tables. Table A is the default table (comes from data
I want to left join two tables. My problem is that the table from
I need to compare two tables and then filter out only those records that
I need to select all entries between two given dates (Nov 10 and Jan
I have used joins to get data from two tables under common name, as
In SQL Server, I am trying to get the rows from the two tables
I am using Entity Framework from .NET 3.5 I have two tables with 0-1

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.