MySQL SELECT from multiple columns from tables











up vote
1
down vote

favorite












I am trying to retrieve information from a mysql database.
I have the following tables:




Qualifications(qualificationid, qualificationname, personid,status)



Address(addressid, addressline1,city,province,areacode,personid)



score(scoreid, score.choices,personid,jobid)




I use typed the following mysql statement to retrieve the data



SELECT score.personid, qualifications.qualificationname, score.score
FROM
Qualifications, Score, Address
WHERE
score.jobid=58
AND
qualifications.qualificationName ='Human Resource Management'
AND
aadress.province ='Western Cape'
ORDER BY score.score
LIMIT 0,20;


this seems to work for everything else but doesn't restrict the province to western cape.










share|improve this question
























  • province is "western cape" just like that? any chance to have space or other chars? you can try: UPPER(RTRIM(LTRIM(aadress.province))) =UPPER(RTRIM(LTRIM('Western Cape'))) ; OR aadress.province LIKE '%Western Cape%'. Hope this helps
    – Anda Iancu
    Aug 27 '13 at 8:50










  • Looks like a typo: address.province instead of aadress.province
    – aross
    Aug 27 '13 at 8:52















up vote
1
down vote

favorite












I am trying to retrieve information from a mysql database.
I have the following tables:




Qualifications(qualificationid, qualificationname, personid,status)



Address(addressid, addressline1,city,province,areacode,personid)



score(scoreid, score.choices,personid,jobid)




I use typed the following mysql statement to retrieve the data



SELECT score.personid, qualifications.qualificationname, score.score
FROM
Qualifications, Score, Address
WHERE
score.jobid=58
AND
qualifications.qualificationName ='Human Resource Management'
AND
aadress.province ='Western Cape'
ORDER BY score.score
LIMIT 0,20;


this seems to work for everything else but doesn't restrict the province to western cape.










share|improve this question
























  • province is "western cape" just like that? any chance to have space or other chars? you can try: UPPER(RTRIM(LTRIM(aadress.province))) =UPPER(RTRIM(LTRIM('Western Cape'))) ; OR aadress.province LIKE '%Western Cape%'. Hope this helps
    – Anda Iancu
    Aug 27 '13 at 8:50










  • Looks like a typo: address.province instead of aadress.province
    – aross
    Aug 27 '13 at 8:52













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to retrieve information from a mysql database.
I have the following tables:




Qualifications(qualificationid, qualificationname, personid,status)



Address(addressid, addressline1,city,province,areacode,personid)



score(scoreid, score.choices,personid,jobid)




I use typed the following mysql statement to retrieve the data



SELECT score.personid, qualifications.qualificationname, score.score
FROM
Qualifications, Score, Address
WHERE
score.jobid=58
AND
qualifications.qualificationName ='Human Resource Management'
AND
aadress.province ='Western Cape'
ORDER BY score.score
LIMIT 0,20;


this seems to work for everything else but doesn't restrict the province to western cape.










share|improve this question















I am trying to retrieve information from a mysql database.
I have the following tables:




Qualifications(qualificationid, qualificationname, personid,status)



Address(addressid, addressline1,city,province,areacode,personid)



score(scoreid, score.choices,personid,jobid)




I use typed the following mysql statement to retrieve the data



SELECT score.personid, qualifications.qualificationname, score.score
FROM
Qualifications, Score, Address
WHERE
score.jobid=58
AND
qualifications.qualificationName ='Human Resource Management'
AND
aadress.province ='Western Cape'
ORDER BY score.score
LIMIT 0,20;


this seems to work for everything else but doesn't restrict the province to western cape.







mysql select multiple-columns multiple-tables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 5:19









Cœur

17k9102140




17k9102140










asked Aug 27 '13 at 8:46









user1783675

1291421




1291421












  • province is "western cape" just like that? any chance to have space or other chars? you can try: UPPER(RTRIM(LTRIM(aadress.province))) =UPPER(RTRIM(LTRIM('Western Cape'))) ; OR aadress.province LIKE '%Western Cape%'. Hope this helps
    – Anda Iancu
    Aug 27 '13 at 8:50










  • Looks like a typo: address.province instead of aadress.province
    – aross
    Aug 27 '13 at 8:52


















  • province is "western cape" just like that? any chance to have space or other chars? you can try: UPPER(RTRIM(LTRIM(aadress.province))) =UPPER(RTRIM(LTRIM('Western Cape'))) ; OR aadress.province LIKE '%Western Cape%'. Hope this helps
    – Anda Iancu
    Aug 27 '13 at 8:50










  • Looks like a typo: address.province instead of aadress.province
    – aross
    Aug 27 '13 at 8:52
















province is "western cape" just like that? any chance to have space or other chars? you can try: UPPER(RTRIM(LTRIM(aadress.province))) =UPPER(RTRIM(LTRIM('Western Cape'))) ; OR aadress.province LIKE '%Western Cape%'. Hope this helps
– Anda Iancu
Aug 27 '13 at 8:50




province is "western cape" just like that? any chance to have space or other chars? you can try: UPPER(RTRIM(LTRIM(aadress.province))) =UPPER(RTRIM(LTRIM('Western Cape'))) ; OR aadress.province LIKE '%Western Cape%'. Hope this helps
– Anda Iancu
Aug 27 '13 at 8:50












Looks like a typo: address.province instead of aadress.province
– aross
Aug 27 '13 at 8:52




Looks like a typo: address.province instead of aadress.province
– aross
Aug 27 '13 at 8:52












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










Why don't you use joins? Like so:



SELECT s.personid, q.qualificationname, s.score
FROM Score s
INNER JOIN Qualifications q ON q.personid = s.personid AND q.qualificationName ='Human Resource Management'
INNER JOIN Address a ON a.personid = s.personid AND a.province ='Western Cape'
WHERE s.jobid = 58
ORDER BY s.score DESC
LIMIT 0,20;





share|improve this answer




























    up vote
    0
    down vote













    You will need to define relations. The system now has no clue how Addresses relate to Scores or Qualifications in your example. By adding a GROUP BY score.personid and AND score.personid = address.personid and score.personid = qualifications.personid you might fix your problems.



    Also, using JOINS is probably more efficient as it does basically the same.






    share|improve this answer





















      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',
      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%2f18460917%2fmysql-select-from-multiple-columns-from-tables%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote



      accepted










      Why don't you use joins? Like so:



      SELECT s.personid, q.qualificationname, s.score
      FROM Score s
      INNER JOIN Qualifications q ON q.personid = s.personid AND q.qualificationName ='Human Resource Management'
      INNER JOIN Address a ON a.personid = s.personid AND a.province ='Western Cape'
      WHERE s.jobid = 58
      ORDER BY s.score DESC
      LIMIT 0,20;





      share|improve this answer

























        up vote
        2
        down vote



        accepted










        Why don't you use joins? Like so:



        SELECT s.personid, q.qualificationname, s.score
        FROM Score s
        INNER JOIN Qualifications q ON q.personid = s.personid AND q.qualificationName ='Human Resource Management'
        INNER JOIN Address a ON a.personid = s.personid AND a.province ='Western Cape'
        WHERE s.jobid = 58
        ORDER BY s.score DESC
        LIMIT 0,20;





        share|improve this answer























          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          Why don't you use joins? Like so:



          SELECT s.personid, q.qualificationname, s.score
          FROM Score s
          INNER JOIN Qualifications q ON q.personid = s.personid AND q.qualificationName ='Human Resource Management'
          INNER JOIN Address a ON a.personid = s.personid AND a.province ='Western Cape'
          WHERE s.jobid = 58
          ORDER BY s.score DESC
          LIMIT 0,20;





          share|improve this answer












          Why don't you use joins? Like so:



          SELECT s.personid, q.qualificationname, s.score
          FROM Score s
          INNER JOIN Qualifications q ON q.personid = s.personid AND q.qualificationName ='Human Resource Management'
          INNER JOIN Address a ON a.personid = s.personid AND a.province ='Western Cape'
          WHERE s.jobid = 58
          ORDER BY s.score DESC
          LIMIT 0,20;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 27 '13 at 8:56









          vollie

          92511017




          92511017
























              up vote
              0
              down vote













              You will need to define relations. The system now has no clue how Addresses relate to Scores or Qualifications in your example. By adding a GROUP BY score.personid and AND score.personid = address.personid and score.personid = qualifications.personid you might fix your problems.



              Also, using JOINS is probably more efficient as it does basically the same.






              share|improve this answer

























                up vote
                0
                down vote













                You will need to define relations. The system now has no clue how Addresses relate to Scores or Qualifications in your example. By adding a GROUP BY score.personid and AND score.personid = address.personid and score.personid = qualifications.personid you might fix your problems.



                Also, using JOINS is probably more efficient as it does basically the same.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You will need to define relations. The system now has no clue how Addresses relate to Scores or Qualifications in your example. By adding a GROUP BY score.personid and AND score.personid = address.personid and score.personid = qualifications.personid you might fix your problems.



                  Also, using JOINS is probably more efficient as it does basically the same.






                  share|improve this answer












                  You will need to define relations. The system now has no clue how Addresses relate to Scores or Qualifications in your example. By adding a GROUP BY score.personid and AND score.personid = address.personid and score.personid = qualifications.personid you might fix your problems.



                  Also, using JOINS is probably more efficient as it does basically the same.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 27 '13 at 9:05









                  Bjorn Schijff

                  2,58521120




                  2,58521120






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18460917%2fmysql-select-from-multiple-columns-from-tables%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

                      Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                      ComboBox Display Member on multiple fields

                      Is it possible to collect Nectar points via Trainline?