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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:57:03+00:00 2026-06-17T23:57:03+00:00

TB 1 : user_profile as ur-> id(PK),name (total 4k records all unique) TB 2

  • 0
TB 1 : user_profile as ur-> id(PK),name (total 4k records all unique)    
TB 2 : user_course_rel as ucr-> id,course_id,year_id,division,user_id(Fk)    
TB 3 : students_attendance_lect as sal-> id,subject_id,date,student_id(Fk)    
student_id(Fk) = user_id(Fk) = id(PK).

I want to left join on TB1 and get name of all students belonging to particular course,year,division and both attendees of subject and date and not attendees which should be 132 unique records.
After running following query i am getting total (4k records)

select distinct(ur.id), ur.fname
from user_profile as ur
inner join user_course_rel as ucr
    on ucr.user_id=ur.id
left join students_attendance_lect as sal
    on sal.student_id=ucr.user_id
    and ucr.course_id=1
    and ucr.year_id=1
    and ucr.division=3
    and sal.subject_id=2
    and sal.date='2013-01-21'
  • 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-17T23:57:04+00:00Added an answer on June 17, 2026 at 11:57 pm

    Several items in your LEFT JOIN look like they should be in a WHERE clause. I’m not 100% clear what your question is but try:

    select distinct(ur.id), ur.fname
    from user_profile as ur
    inner join user_course_rel as ucr
        on ucr.user_id=ur.id
    left join
        (SELECT sal.student_id, sal.subject_id, sal.date
         FROM students_attendance_lect as sal
         WHERE sal.date='2013-01-21'
         AND sal.subject_id = 2) AS sa
        ON sa.student_id=ucr.user_id
    WHERE ucr.course_id=1
        and ucr.year_id=1
        and ucr.division=3
    

    The way you had written it was asking the DB to LEFT JOIN on any row that had a course id of 1, a division of 3, a subject id of 2 or a date of ‘2013-01-21’, do you see?

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

Sidebar

Related Questions

My Response data looks like this {page:1,total:10,records:8,message:null,rowdata: [{status:null,contactNo:null,approvalStatus:null,userInfoID:32,userName:bbb 1234,userFullName:bbb 1234,profiles:[{profileInfoID:10,profileName:Profile Ganda},{profileInfoID:15,profileName:Sample Profile 123}]}, {status:null,contactNo:null,approvalStatus:null,userInfoID:28,userName:
What is the correct way to refer to current_user.user_profile.name when there may or may
I have two models: User (email:string) Profile (name:string) class User < ActiveRecord::Base has_one :profile
Supposing that I have millions of user profiles, with hundreds of fields (name, gender,
I have a User table with 1m records: User (id, fname, lname, deleted_at, guest)
I know generally it is always better performance to build mysql queries to name
I have this code inside my view. $country = array( 'id' => 'country', 'name'
I'm using django comments frameworks . All the comments are posted by authenticated users.
I want to display country name instead of country id in user profile view(
I have table Users which contains columns: id, name, points, extra_points. How can I

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.