Fetch data of two tables with/without match of Primary key and foreign key Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Can I concatenate multiple MySQL rows into one field?SQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?How to select rows with no matching entry in another table?Delete all Duplicate Rows except for One in MySQL?Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraintsSQL select only rows with max value on a columnSelect last record for each foreign key that match primary keyError no primary key in a table with two foreign keyHow to match multiple tables foreign keys to another tables primary key

What would you call this weird metallic apparatus that allows you to lift people?

What does it mean that physics no longer uses mechanical models to describe phenomena?

A term for a woman complaining about things/begging in a cute/childish way

What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

What do you call the main part of a joke?

Putting class ranking in CV, but against dept guidelines

Is there hard evidence that the grant peer review system performs significantly better than random?

How to tell that you are a giant?

Disembodied hand growing fangs

How much damage would a cupful of neutron star matter do to the Earth?

How come Sam didn't become Lord of Horn Hill?

Can a new player join a group only when a new campaign starts?

Why should I vote and accept answers?

How to write the following sign?

Crossing US/Canada Border for less than 24 hours

How to play a character with a disability or mental disorder without being offensive?

How does the secondary effect of the Heat Metal spell interact with a creature resistant/immune to fire damage?

SF book about people trapped in a series of worlds they imagine

Did Deadpool rescue all of the X-Force?

Effects on objects due to a brief relocation of massive amounts of mass

Why weren't discrete x86 CPUs ever used in game hardware?

Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?

An adverb for when you're not exaggerating



Fetch data of two tables with/without match of Primary key and foreign key



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Can I concatenate multiple MySQL rows into one field?SQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?How to select rows with no matching entry in another table?Delete all Duplicate Rows except for One in MySQL?Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraintsSQL select only rows with max value on a columnSelect last record for each foreign key that match primary keyError no primary key in a table with two foreign keyHow to match multiple tables foreign keys to another tables primary key



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am using this query.



select * from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)


Here E.ID is primary key of customers table and p_ID is foreign key of customer_p
This query fetches only those result in which primary key (ID) of customers table is present as foreign key (P__ID) of customer_p table and skips rest rows/data from customers table.



I want to fetch all date of customers table whether or not primary key (ID) do match with foreign key (P__ID). How can I do this?










share|improve this question

















  • 1





    That is why there is a Left Join

    – ArtisticPhoenix
    Mar 22 at 9:55






  • 1





    I dont know, if I understand correctly, but try LEFT JOIN -> select * from customers E LEFT JOIN customer_p D ON (E.ID = D.P_ID)

    – Autista_z
    Mar 22 at 9:55


















1















I am using this query.



select * from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)


Here E.ID is primary key of customers table and p_ID is foreign key of customer_p
This query fetches only those result in which primary key (ID) of customers table is present as foreign key (P__ID) of customer_p table and skips rest rows/data from customers table.



I want to fetch all date of customers table whether or not primary key (ID) do match with foreign key (P__ID). How can I do this?










share|improve this question

















  • 1





    That is why there is a Left Join

    – ArtisticPhoenix
    Mar 22 at 9:55






  • 1





    I dont know, if I understand correctly, but try LEFT JOIN -> select * from customers E LEFT JOIN customer_p D ON (E.ID = D.P_ID)

    – Autista_z
    Mar 22 at 9:55














1












1








1








I am using this query.



select * from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)


Here E.ID is primary key of customers table and p_ID is foreign key of customer_p
This query fetches only those result in which primary key (ID) of customers table is present as foreign key (P__ID) of customer_p table and skips rest rows/data from customers table.



I want to fetch all date of customers table whether or not primary key (ID) do match with foreign key (P__ID). How can I do this?










share|improve this question














I am using this query.



select * from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)


Here E.ID is primary key of customers table and p_ID is foreign key of customer_p
This query fetches only those result in which primary key (ID) of customers table is present as foreign key (P__ID) of customer_p table and skips rest rows/data from customers table.



I want to fetch all date of customers table whether or not primary key (ID) do match with foreign key (P__ID). How can I do this?







php sql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 9:52









RishabhRishabh

3102618




3102618







  • 1





    That is why there is a Left Join

    – ArtisticPhoenix
    Mar 22 at 9:55






  • 1





    I dont know, if I understand correctly, but try LEFT JOIN -> select * from customers E LEFT JOIN customer_p D ON (E.ID = D.P_ID)

    – Autista_z
    Mar 22 at 9:55













  • 1





    That is why there is a Left Join

    – ArtisticPhoenix
    Mar 22 at 9:55






  • 1





    I dont know, if I understand correctly, but try LEFT JOIN -> select * from customers E LEFT JOIN customer_p D ON (E.ID = D.P_ID)

    – Autista_z
    Mar 22 at 9:55








1




1





That is why there is a Left Join

– ArtisticPhoenix
Mar 22 at 9:55





That is why there is a Left Join

– ArtisticPhoenix
Mar 22 at 9:55




1




1





I dont know, if I understand correctly, but try LEFT JOIN -> select * from customers E LEFT JOIN customer_p D ON (E.ID = D.P_ID)

– Autista_z
Mar 22 at 9:55






I dont know, if I understand correctly, but try LEFT JOIN -> select * from customers E LEFT JOIN customer_p D ON (E.ID = D.P_ID)

– Autista_z
Mar 22 at 9:55













3 Answers
3






active

oldest

votes


















1














Use LEFT JOIN instead of JOIN to get all rows in customers.
see https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins






share|improve this answer






























    1














    Please run below query:



    SELECT E.*, D.* 
    FROM customers as E
    LEFT JOIN `customer_p` as D ON D.P_ID = E.ID





    share|improve this answer
































      0














      select date from customers where not
      (
      select date from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)
      )





      share|improve this answer























      • Please add some explanation to your query such that others can learn from it

        – Nico Haase
        Mar 22 at 10:19











      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296971%2ffetch-data-of-two-tables-with-without-match-of-primary-key-and-foreign-key%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Use LEFT JOIN instead of JOIN to get all rows in customers.
      see https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins






      share|improve this answer



























        1














        Use LEFT JOIN instead of JOIN to get all rows in customers.
        see https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins






        share|improve this answer

























          1












          1








          1







          Use LEFT JOIN instead of JOIN to get all rows in customers.
          see https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins






          share|improve this answer













          Use LEFT JOIN instead of JOIN to get all rows in customers.
          see https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 9:59









          vr138vr138

          511




          511























              1














              Please run below query:



              SELECT E.*, D.* 
              FROM customers as E
              LEFT JOIN `customer_p` as D ON D.P_ID = E.ID





              share|improve this answer





























                1














                Please run below query:



                SELECT E.*, D.* 
                FROM customers as E
                LEFT JOIN `customer_p` as D ON D.P_ID = E.ID





                share|improve this answer



























                  1












                  1








                  1







                  Please run below query:



                  SELECT E.*, D.* 
                  FROM customers as E
                  LEFT JOIN `customer_p` as D ON D.P_ID = E.ID





                  share|improve this answer















                  Please run below query:



                  SELECT E.*, D.* 
                  FROM customers as E
                  LEFT JOIN `customer_p` as D ON D.P_ID = E.ID






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 1 at 3:33









                  Rich

                  1,73271831




                  1,73271831










                  answered Mar 22 at 10:05









                  PuneetPuneet

                  12




                  12





















                      0














                      select date from customers where not
                      (
                      select date from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)
                      )





                      share|improve this answer























                      • Please add some explanation to your query such that others can learn from it

                        – Nico Haase
                        Mar 22 at 10:19















                      0














                      select date from customers where not
                      (
                      select date from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)
                      )





                      share|improve this answer























                      • Please add some explanation to your query such that others can learn from it

                        – Nico Haase
                        Mar 22 at 10:19













                      0












                      0








                      0







                      select date from customers where not
                      (
                      select date from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)
                      )





                      share|improve this answer













                      select date from customers where not
                      (
                      select date from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`)
                      )






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 22 at 9:56









                      esnkrimiesnkrimi

                      883




                      883












                      • Please add some explanation to your query such that others can learn from it

                        – Nico Haase
                        Mar 22 at 10:19

















                      • Please add some explanation to your query such that others can learn from it

                        – Nico Haase
                        Mar 22 at 10:19
















                      Please add some explanation to your query such that others can learn from it

                      – Nico Haase
                      Mar 22 at 10:19





                      Please add some explanation to your query such that others can learn from it

                      – Nico Haase
                      Mar 22 at 10:19

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55296971%2ffetch-data-of-two-tables-with-without-match-of-primary-key-and-foreign-key%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript