join query not fetching any data

AL-zami

i am trying to write my first join query which will help me to join two different tables,one is for students and other is for subjects.This is my first join query and it seems it is not working,can anyone point out the mistakes.Php didn't show any error or worning

enter image description here enter image description here

   try{
     $pdo=new PDO("mysql:host=localhost;dbname=mydb",'root','');
     $sql="SELECT * FROM students LEFT JOIN subjects WHERE students.courseid=subjects.courseid";
     $conn=$pdo->prepare($sql);
      if($conn->execute()){
        $results=$conn->fetchAll();
        print_r($results);
      }
     }catch(PDOException $e){
         echo $e->getMessage();
     }
davejal

Assuming you table name for students is students and you subjects table is subject then I think it should be:

SELECT * FROM students LEFT JOIN subjects on students.courseid=subjects.subjectid

because you have a subjectid in your subjects table and not courseid

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP / MySQL - Query not fetching any data

From Dev

OpenJPA join query does not return any data

From Dev

Put data in WHERE clause condition without fetching it | And remove duplication in Left Join query

From Dev

Grouping the data after fetching the query

From Dev

Nested query not fetching data correctly

From Dev

Fetching wrong data in query in rails

From Dev

sql query error data not fetching data proprerly

From Dev

Fetching data only for specified mapping in HQL query

From Dev

SQL query for fetching data from multiple tables

From Dev

Fetching form data through query string in flask

From Dev

Mysql query is not fetching data as i want

From Dev

Error in database class in data fetching query

From Dev

Fetching data issue using simple like query

From Dev

Fetching data only for specified mapping in HQL query

From Dev

Fetching data from MySQL, problems with diferent query

From Dev

element-attribute-range-query fetching result but element-attribute-value-query is not fetching any result

From Dev

Getting unspecified data while fetching data using mongoose find query

From Dev

How to calculate Fetching Time while fetching data from any Api in Ajax

From Dev

native query join in spring data

From Dev

Join multiple rows of data to query

From Dev

create mysql query for fetching data in 3 days slotwise

From Dev

Parse background job query iterations are returning before fetching data

From Dev

Select query is not working while fetching data from database

From Dev

Fetching Data from XML along with the Conditions in a single Query

From Dev

Fetching data from SharePoint List ithout using CAML query

From Dev

if Query doesnt not return any data

From Dev

Fetching other rows of table when performing inner join over multiple fields (oracle query)

From Dev

Mysqli query fetching no records

From Dev

Query in MongoDb for fetching record

Related Related

  1. 1

    PHP / MySQL - Query not fetching any data

  2. 2

    OpenJPA join query does not return any data

  3. 3

    Put data in WHERE clause condition without fetching it | And remove duplication in Left Join query

  4. 4

    Grouping the data after fetching the query

  5. 5

    Nested query not fetching data correctly

  6. 6

    Fetching wrong data in query in rails

  7. 7

    sql query error data not fetching data proprerly

  8. 8

    Fetching data only for specified mapping in HQL query

  9. 9

    SQL query for fetching data from multiple tables

  10. 10

    Fetching form data through query string in flask

  11. 11

    Mysql query is not fetching data as i want

  12. 12

    Error in database class in data fetching query

  13. 13

    Fetching data issue using simple like query

  14. 14

    Fetching data only for specified mapping in HQL query

  15. 15

    Fetching data from MySQL, problems with diferent query

  16. 16

    element-attribute-range-query fetching result but element-attribute-value-query is not fetching any result

  17. 17

    Getting unspecified data while fetching data using mongoose find query

  18. 18

    How to calculate Fetching Time while fetching data from any Api in Ajax

  19. 19

    native query join in spring data

  20. 20

    Join multiple rows of data to query

  21. 21

    create mysql query for fetching data in 3 days slotwise

  22. 22

    Parse background job query iterations are returning before fetching data

  23. 23

    Select query is not working while fetching data from database

  24. 24

    Fetching Data from XML along with the Conditions in a single Query

  25. 25

    Fetching data from SharePoint List ithout using CAML query

  26. 26

    if Query doesnt not return any data

  27. 27

    Fetching other rows of table when performing inner join over multiple fields (oracle query)

  28. 28

    Mysqli query fetching no records

  29. 29

    Query in MongoDb for fetching record

HotTag

Archive