Two mysql select queries into one queryHow to get non-deleted messages for one user_id if the same user_id...

How can I differentiate duration vs starting time

Sri Keyuravati of krama tradition

What could cause an entire planet of humans to become aphasic?

Boss asked me to sign a resignation paper without a date on it along with my new contract

Why do objects rebound after hitting the ground?

How to deal with an underperforming subordinate?

How can I handle players killing my NPC outside of combat?

Putting a vertical line in each Histogram using GraphicsGrid

Did ancient Germans take pride in leaving the land untouched?

How to get a 2D Plot from a 3D Listplot?

In a post-apocalypse world, with no power and few survivors, would Satnav still work?

Was there a pre-determined arrangement for the division of Germany in case it surrendered before any Soviet forces entered its territory?

Would water spill from a bowl in a Bag of Holding?

Is "accuse people to be racist" grammatical?

Is Screenshot Time-tracking Common?

How to know if I am a 'Real Developer'

How can I put a period right after the algorithm's number in the algorithm's title?

Modern Algebraic Geometry and Analytic Number Theory

Can I legally make a website about boycotting a certain company?

Maybe pigeonhole problem?

What does an unprocessed RAW file look like?

Bursted bubble like details on material

"I showed the monkey himself in the mirror". Why is this sentence grammatical?

I have trouble understanding this fallacy: "If A, then B. Therefore if not-B, then not-A."



Two mysql select queries into one query


How to get non-deleted messages for one user_id if the same user_id appears in two tables at same time?Can I execute a prepared statement inside a MySQL SELECT?Slow performance of MySQL Join QueryMySQL Query Optimization - Indexes & Joins 12 million+ recordscompare results between two select queries MySQLPrivilege to select only user's own tuple only in mysqlHelp combining two MySQL queries to improve performanceHow to combine “SELECT” and “REPLACE INTO” when combining two MySQL tables into another?Does MySQL allows incoming queries while altering a table?SQL schema for movie rating and seenlist













0















user



id   |  name
1 | A
2 | B


article



id   | title | descritption
1 | wx | xyz
2 | yz | abc


article_rating



article_id(article->id)  |  given_by(user->id)  |  given_rating
1 2 4
2 1 3


saved_article



article_id(article->id)  |  saved_by(user->id) 
1 2


I'm changing some buttons and icons depending on whether a user has rated/ saved an article or not. I'm using two select queries for that:



rated or not



SELECT given_rating as rating 
FROM article_rating
WHERE given_by=? AND article_id=?


saved or not



SELECT saved_by as saved 
FROM saved_article
WHERE saved_by=? AND article_id=?


So my question is how can i combine both into one mysql query efficiently??










share|improve this question





























    0















    user



    id   |  name
    1 | A
    2 | B


    article



    id   | title | descritption
    1 | wx | xyz
    2 | yz | abc


    article_rating



    article_id(article->id)  |  given_by(user->id)  |  given_rating
    1 2 4
    2 1 3


    saved_article



    article_id(article->id)  |  saved_by(user->id) 
    1 2


    I'm changing some buttons and icons depending on whether a user has rated/ saved an article or not. I'm using two select queries for that:



    rated or not



    SELECT given_rating as rating 
    FROM article_rating
    WHERE given_by=? AND article_id=?


    saved or not



    SELECT saved_by as saved 
    FROM saved_article
    WHERE saved_by=? AND article_id=?


    So my question is how can i combine both into one mysql query efficiently??










    share|improve this question



























      0












      0








      0








      user



      id   |  name
      1 | A
      2 | B


      article



      id   | title | descritption
      1 | wx | xyz
      2 | yz | abc


      article_rating



      article_id(article->id)  |  given_by(user->id)  |  given_rating
      1 2 4
      2 1 3


      saved_article



      article_id(article->id)  |  saved_by(user->id) 
      1 2


      I'm changing some buttons and icons depending on whether a user has rated/ saved an article or not. I'm using two select queries for that:



      rated or not



      SELECT given_rating as rating 
      FROM article_rating
      WHERE given_by=? AND article_id=?


      saved or not



      SELECT saved_by as saved 
      FROM saved_article
      WHERE saved_by=? AND article_id=?


      So my question is how can i combine both into one mysql query efficiently??










      share|improve this question
















      user



      id   |  name
      1 | A
      2 | B


      article



      id   | title | descritption
      1 | wx | xyz
      2 | yz | abc


      article_rating



      article_id(article->id)  |  given_by(user->id)  |  given_rating
      1 2 4
      2 1 3


      saved_article



      article_id(article->id)  |  saved_by(user->id) 
      1 2


      I'm changing some buttons and icons depending on whether a user has rated/ saved an article or not. I'm using two select queries for that:



      rated or not



      SELECT given_rating as rating 
      FROM article_rating
      WHERE given_by=? AND article_id=?


      saved or not



      SELECT saved_by as saved 
      FROM saved_article
      WHERE saved_by=? AND article_id=?


      So my question is how can i combine both into one mysql query efficiently??







      mysql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 mins ago







      Share corn

















      asked 18 mins ago









      Share cornShare corn

      1




      1






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fdba.stackexchange.com%2fquestions%2f230611%2ftwo-mysql-select-queries-into-one-query%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • 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%2fdba.stackexchange.com%2fquestions%2f230611%2ftwo-mysql-select-queries-into-one-query%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

          Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

          Lupi Siderali Indice Storia | Organizzazione | La Tredicesima Compagnia | Aspetto | Membri Importanti...

          Armoriale delle famiglie italiane (Car) Indice Armi | Bibliografia | Menu di navigazioneBlasone...