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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:42:44+00:00 2026-05-29T16:42:44+00:00

I have 2 tables: users and log. Currently my query looks like that. $stmt

  • 0

I have 2 tables: users and log. Currently my query looks like that.

        $stmt = $this->db->prepare("SELECT u.id, u.email, u.salt, u.pass, u.approved, u.ban, u2.status  FROM `users` AS u LEFT OUTER JOIN `log` AS u2 ON u2.user_id = u.id WHERE u.email = ?") or die($this->db->error);
        $stmt->bind_param("s", $_POST['email']) or die($stmt->error);
        $stmt->execute();
        $stmt->store_result();
        if ($stmt->num_rows == 0) {
            die($this->ajax->respond(7));
        }
        $data = array();
        $stmt->bind_result($data['id'], $data['email'], $data['salt'], $data['pass'], $data['approved'], $data['ban'], $data['status']) or die($stmt->error);
        $stmt->fetch() or die($stmt->error);
        $stmt->close() or die($stmt->error);

Status column of log table – is indicates if user already signed in or not. What I want to do is to check if email exists in users table and to count rows of log table where status=1. Is that possible with one and only query?

In other words:

Here is log table

enter image description here

Take a look at rows where status = 1. This indicates that user 1 currently signed in. To prevent second signin from different browser I want to at first check for email in users table (basic signin procedure) and at that moment check if user not signed in (by counting rows where status = 1 in log 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-29T16:42:50+00:00Added an answer on May 29, 2026 at 4:42 pm

    Just change the query to this –

    SELECT u.id, u.email, u.salt, u.pass, u.approved, 
    u.ban, SUM(u2.status) AS status FROM `users` AS u 
    LEFT JOIN `log` AS u2 ON u2.user_id = u.id 
    WHERE u.email = ?
    GROUP BY u.id
    

    There are a number of other ways to do this as well.

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

Sidebar

Related Questions

Imagine I have a service that looks like this: public interface MyAccountService { boolean
I have two tables user and log. I would like to join the user
I have a table that functions as an event log and stores the users
I have a couple of tables which are used to log user activity for
I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id,
I have 3 tables users(id,name),groups(id,name) and users_groups(user_id,group_id). users and groups have many to many
I have two tables: Users: ID, first_name, last_name Networks: user_id, friend_id, status I want
I have several variables in an SSIS package that I would like inserting into
I have this idea which I need some help with. Currently I am developing
I have table of users called users and log table called ulog . Every

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.