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.
mysql select multiple-columns multiple-tables
add a comment |
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.
mysql select multiple-columns multiple-tables
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
add a comment |
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.
mysql select multiple-columns multiple-tables
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
mysql select multiple-columns multiple-tables
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
add a comment |
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
add a comment |
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;
add a comment |
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.
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Aug 27 '13 at 8:56
vollie
92511017
92511017
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Aug 27 '13 at 9:05
Bjorn Schijff
2,58521120
2,58521120
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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