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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:33:35+00:00 2026-05-16T11:33:35+00:00

I have a Users table and a Payments table. I need a query which

  • 0

I have a Users table and a Payments table. I need a query which lists the users who have a record in the payments table where PaymentStatus=1.

It must also only list users with a certain GroupID. The GroupID will be passed by a variable, but we can just call it 5 for simplicity.

The timestamp of the record (TimeCompleted) must also be less than a set timestamp, but we can just call this 10.

These are the columns in the tables (simplified):

     Users: UserID, GroupID, UserName
  Payments: PaymentID, UserID, PaymentStatus, TimeCompleted

The query should select the field UserName.

I did ask a similar question a few hours ago, but I asked it wrong and I couldn’t get the queries to work properly for me. Also – if the user has more than one valid and active payment, it must only return the UserName once. When I tried to do it, I couldn’t do this.

You can improve on my current query if you want to (it does everything apart from the last problem about duplicating the returned users). I might be going about it completely wrong though:

         SELECT `Users`.`UserName`
           FROM `Users`
LEFT OUTER JOIN `Payments` ON `Users`.`UserID` = `Payments`.`UserID`
          WHERE `Payments`.`TimeCompleted` < 10
            AND `Payments`.`PaymentStatus` = 1
            AND `Users`.`GroupID` = 5
  • 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-16T11:33:35+00:00Added an answer on May 16, 2026 at 11:33 am

    You want to join across the two tables using the UserId key. The group by clause will limit to distinct username:

    select UserName 
    from Users inner join Payments on (Users.UserID = Payments.UserID)
    where PaymentStatus = 1 and GroupID = 5 and TimeCompleted < 10 group by Users.UserID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Users table and a Payments table. I need a query which
Let say I have table Payments Id int autoincement Status int and my query
I'm using SQL-Server 2005. I have two tables Users and Payments which has a
I have a table called users where the employee data are stored. Also I
I have a payments table that has a user_id and an amount. Users have
I have table structure like below: events (boxing, sparring etc) competitors (users who are
I have users table and want to SELECT some rows by bitmask criteria. I'll
I have users table. There are three other tables: developers, managers, testers. All of
i have users table and i have posts table i want select from users
I have a users table and a blocked_users table. users has all my authentication

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.