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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:37:11+00:00 2026-05-27T22:37:11+00:00

Trying to get an INNER JOIN to work is driving me insane, so I’m

  • 0

Trying to get an INNER JOIN to work is driving me insane, so I’m very much hoping that someone can help me out here.

I have two tables in a database:

BranchEmployees
DepartmentEmployees

Both tables have a column called EmpID so I can track which employees are assigned to which department and to which branch. I’m making a report that finds which employees are assigned to a specified department and branch, excluding all the rest so an INNER JOIN query seems like the logical solution, but we just cannot get it to work. We keep getting the fatal error:

Fatal error: Call to a member function fetchAll() on a non-object in ...

$query="SELECT DepartmentEmployees.EmpID FROM DepartmentEmployees INNER JOIN BranchEmployees ON  DepartmentEmployees.EmpID=BranchEmployees.EmpID";

$connect=$cdb->query($query);
$EmployeeList[$m]=$connect->fetchAll(PDO::FETCH_ASSOC);

Does it matter that it’s on a shared server when trying to INNER JOIN tables? I don’t think it should from what I can read, but you never know.

  • 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-27T22:37:11+00:00Added an answer on May 27, 2026 at 10:37 pm
    <?php
    try {
        $db = new PDO("mysql:host=localhost;dbname=yourDBName", 'root', 'pass', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") );
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    
        $sql = 'SELECT de.EmpID FROM DepartmentEmployees as de INNER JOIN BranchEmployees as be ON de.EmpID = be.EmpID';
    
        $sth = $db->query($sql);
    }
    catch(PDOException $e) {
        # There was an error, die
        die('There was an error.');
    }
    
    $sth->setFetchMode(PDO::FETCH_ASSOC);
    $result = $sth->fetchAll();
    
    var_dump($result);
    ?>
    

    Just change this line for db connection, query should work;

    $db = new PDO("mysql:host=localhost;dbname=yourDBName", 'root', 'pass', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") );
    

    I hope this helps.

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

Sidebar

Related Questions

I'm trying join in Rails 3 for the first time, and can't get the
I am trying my first join and the sql that it's generating is very
I am having trouble trying to get iterators for inner sub-containers. Basically imagine this
Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
Trying to get a JSON output to work with jqGrid 'userdata' option. The example
I'm trying to select multiple rows over different tables but I can't get it
I'm trying to get the following SQL statement to work: UPDATE myschema.tableA update_tableA SET
I have a MySQL query that is trying to get all the Pages that
I am trying to get a random record from a join, but I cannot

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.