Invalid identifier when using left outer join in SQL
up vote
0
down vote
favorite
I get this error for the below code.
Invalid identifier
Any suggestions?
SELECT
subjects.neptuncode AS "neptuncode",
subjects.subjectname AS "subjectname",
enrollments.examdate AS "examdate"
FROM
subjects, enrollments
LEFT OUTER JOIN
enrollments ON enrollments.subject = subjects.subject_ID
HAVING
COUNT(enrollments.enrollmentdate) = 1
ORDER BY
subjects.neptuncode, subjects.subjectname, enrollments.examdate;
sql
add a comment |
up vote
0
down vote
favorite
I get this error for the below code.
Invalid identifier
Any suggestions?
SELECT
subjects.neptuncode AS "neptuncode",
subjects.subjectname AS "subjectname",
enrollments.examdate AS "examdate"
FROM
subjects, enrollments
LEFT OUTER JOIN
enrollments ON enrollments.subject = subjects.subject_ID
HAVING
COUNT(enrollments.enrollmentdate) = 1
ORDER BY
subjects.neptuncode, subjects.subjectname, enrollments.examdate;
sql
You should explain what you want to do, given that your query has multiple errors. A database tag is also helpful.
– Gordon Linoff
Nov 8 at 18:56
enrollments LEFT OUTER JOIN enrollments ...
– jarlh
Nov 8 at 20:28
Bad habits to kick : using old-style JOINs - that old-style comma-separated list of tables style was replaced with the proper ANSIJOIN
syntax in the ANSI-92 SQL Standard (more than 25 years ago) and its use is discouraged
– marc_s
Nov 8 at 21:22
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I get this error for the below code.
Invalid identifier
Any suggestions?
SELECT
subjects.neptuncode AS "neptuncode",
subjects.subjectname AS "subjectname",
enrollments.examdate AS "examdate"
FROM
subjects, enrollments
LEFT OUTER JOIN
enrollments ON enrollments.subject = subjects.subject_ID
HAVING
COUNT(enrollments.enrollmentdate) = 1
ORDER BY
subjects.neptuncode, subjects.subjectname, enrollments.examdate;
sql
I get this error for the below code.
Invalid identifier
Any suggestions?
SELECT
subjects.neptuncode AS "neptuncode",
subjects.subjectname AS "subjectname",
enrollments.examdate AS "examdate"
FROM
subjects, enrollments
LEFT OUTER JOIN
enrollments ON enrollments.subject = subjects.subject_ID
HAVING
COUNT(enrollments.enrollmentdate) = 1
ORDER BY
subjects.neptuncode, subjects.subjectname, enrollments.examdate;
sql
sql
edited Nov 8 at 21:22
marc_s
568k12810991249
568k12810991249
asked Nov 8 at 18:50
Emil Bədrəddinli
356
356
You should explain what you want to do, given that your query has multiple errors. A database tag is also helpful.
– Gordon Linoff
Nov 8 at 18:56
enrollments LEFT OUTER JOIN enrollments ...
– jarlh
Nov 8 at 20:28
Bad habits to kick : using old-style JOINs - that old-style comma-separated list of tables style was replaced with the proper ANSIJOIN
syntax in the ANSI-92 SQL Standard (more than 25 years ago) and its use is discouraged
– marc_s
Nov 8 at 21:22
add a comment |
You should explain what you want to do, given that your query has multiple errors. A database tag is also helpful.
– Gordon Linoff
Nov 8 at 18:56
enrollments LEFT OUTER JOIN enrollments ...
– jarlh
Nov 8 at 20:28
Bad habits to kick : using old-style JOINs - that old-style comma-separated list of tables style was replaced with the proper ANSIJOIN
syntax in the ANSI-92 SQL Standard (more than 25 years ago) and its use is discouraged
– marc_s
Nov 8 at 21:22
You should explain what you want to do, given that your query has multiple errors. A database tag is also helpful.
– Gordon Linoff
Nov 8 at 18:56
You should explain what you want to do, given that your query has multiple errors. A database tag is also helpful.
– Gordon Linoff
Nov 8 at 18:56
enrollments LEFT OUTER JOIN enrollments ...
– jarlh
Nov 8 at 20:28
enrollments LEFT OUTER JOIN enrollments ...
– jarlh
Nov 8 at 20:28
Bad habits to kick : using old-style JOINs - that old-style comma-separated list of tables style was replaced with the proper ANSI
JOIN
syntax in the ANSI-92 SQL Standard (more than 25 years ago) and its use is discouraged– marc_s
Nov 8 at 21:22
Bad habits to kick : using old-style JOINs - that old-style comma-separated list of tables style was replaced with the proper ANSI
JOIN
syntax in the ANSI-92 SQL Standard (more than 25 years ago) and its use is discouraged– marc_s
Nov 8 at 21:22
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
Change this line
FROM subjects, enrollments
to
FROM subjects
You shouldn't mix the old style of joins (comma delimited) and explicit joins. Really you shouldn't use comma delimited joins as they were essentially replaced many, many years ago.
You can, but not on the same table without proper aliases (and you shouldn't be using implicit joins anyway, since explicit joins are a part of ANSI-SQL for almost 30 years now...)
– Zohar Peled
Nov 8 at 18:53
1
IMHO one shouldn't mix old comma-syntax joins with any other query that contains characters. :-)
– Shawn
Nov 8 at 18:53
Just a pedantic comment: some databases allow you to mix old & new style joins. It's confusing to me, and my take is they shouldn't be allowed. But they do.
– The Impaler
Nov 8 at 18:53
Thanks for the feedback; answer updated.
– UnhandledExcepSean
Nov 8 at 18:54
@TheImpaler, the old style comma separated joins are still in the SQL standard, can't really be removed... But don't use them when writing new code!
– jarlh
Nov 8 at 20:29
add a comment |
up vote
1
down vote
FROM subjects, enrollments
There's your problem.
Change that to FROM subjects
- problem solved.
add a comment |
up vote
1
down vote
I think the query you want is:
SELECT s.neptuncode, s.subjectname, MAX(e.examdate) as "examdate"
FROM subjects s JOIN
enrollments e
ON e.subject = s.subject_ID
GROUP BY s.neptuncode, s.subjectname
HAVING COUNT(*) = 1
ORDER BY s.neptuncode, s.subjectname;
This returns the exam date for subjects that have only one enrollee.
Notes:
Never use commas in theFROM
clause. Always use proper explicitJOIN
syntax.- A
LEFT JOIN
is not needed. YourHAVING
clause suggests that you want exactly one match. - You should be using
GROUP BY
; theHAVING
presupposes that you want to aggregate. - There is no need to include the exam date in the
ORDER BY
, because there is only one row per neptun code and subject.
Thanks a lot I got the idea. But how can I list the codes(neptuncode) and names of all subjects(subjectname) in case of those subjects, for which any of the students registered for the first time, list exam date for this condition.
– Emil Bədrəddinli
Nov 8 at 19:14
2
@EmilBədrəddinli . . . You should ask a new question as a new question. Along the way, it is good practice to accept an answer for this question.
– Gordon Linoff
Nov 8 at 19:33
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Change this line
FROM subjects, enrollments
to
FROM subjects
You shouldn't mix the old style of joins (comma delimited) and explicit joins. Really you shouldn't use comma delimited joins as they were essentially replaced many, many years ago.
You can, but not on the same table without proper aliases (and you shouldn't be using implicit joins anyway, since explicit joins are a part of ANSI-SQL for almost 30 years now...)
– Zohar Peled
Nov 8 at 18:53
1
IMHO one shouldn't mix old comma-syntax joins with any other query that contains characters. :-)
– Shawn
Nov 8 at 18:53
Just a pedantic comment: some databases allow you to mix old & new style joins. It's confusing to me, and my take is they shouldn't be allowed. But they do.
– The Impaler
Nov 8 at 18:53
Thanks for the feedback; answer updated.
– UnhandledExcepSean
Nov 8 at 18:54
@TheImpaler, the old style comma separated joins are still in the SQL standard, can't really be removed... But don't use them when writing new code!
– jarlh
Nov 8 at 20:29
add a comment |
up vote
2
down vote
Change this line
FROM subjects, enrollments
to
FROM subjects
You shouldn't mix the old style of joins (comma delimited) and explicit joins. Really you shouldn't use comma delimited joins as they were essentially replaced many, many years ago.
You can, but not on the same table without proper aliases (and you shouldn't be using implicit joins anyway, since explicit joins are a part of ANSI-SQL for almost 30 years now...)
– Zohar Peled
Nov 8 at 18:53
1
IMHO one shouldn't mix old comma-syntax joins with any other query that contains characters. :-)
– Shawn
Nov 8 at 18:53
Just a pedantic comment: some databases allow you to mix old & new style joins. It's confusing to me, and my take is they shouldn't be allowed. But they do.
– The Impaler
Nov 8 at 18:53
Thanks for the feedback; answer updated.
– UnhandledExcepSean
Nov 8 at 18:54
@TheImpaler, the old style comma separated joins are still in the SQL standard, can't really be removed... But don't use them when writing new code!
– jarlh
Nov 8 at 20:29
add a comment |
up vote
2
down vote
up vote
2
down vote
Change this line
FROM subjects, enrollments
to
FROM subjects
You shouldn't mix the old style of joins (comma delimited) and explicit joins. Really you shouldn't use comma delimited joins as they were essentially replaced many, many years ago.
Change this line
FROM subjects, enrollments
to
FROM subjects
You shouldn't mix the old style of joins (comma delimited) and explicit joins. Really you shouldn't use comma delimited joins as they were essentially replaced many, many years ago.
edited Nov 8 at 18:54
answered Nov 8 at 18:51
UnhandledExcepSean
9,60522040
9,60522040
You can, but not on the same table without proper aliases (and you shouldn't be using implicit joins anyway, since explicit joins are a part of ANSI-SQL for almost 30 years now...)
– Zohar Peled
Nov 8 at 18:53
1
IMHO one shouldn't mix old comma-syntax joins with any other query that contains characters. :-)
– Shawn
Nov 8 at 18:53
Just a pedantic comment: some databases allow you to mix old & new style joins. It's confusing to me, and my take is they shouldn't be allowed. But they do.
– The Impaler
Nov 8 at 18:53
Thanks for the feedback; answer updated.
– UnhandledExcepSean
Nov 8 at 18:54
@TheImpaler, the old style comma separated joins are still in the SQL standard, can't really be removed... But don't use them when writing new code!
– jarlh
Nov 8 at 20:29
add a comment |
You can, but not on the same table without proper aliases (and you shouldn't be using implicit joins anyway, since explicit joins are a part of ANSI-SQL for almost 30 years now...)
– Zohar Peled
Nov 8 at 18:53
1
IMHO one shouldn't mix old comma-syntax joins with any other query that contains characters. :-)
– Shawn
Nov 8 at 18:53
Just a pedantic comment: some databases allow you to mix old & new style joins. It's confusing to me, and my take is they shouldn't be allowed. But they do.
– The Impaler
Nov 8 at 18:53
Thanks for the feedback; answer updated.
– UnhandledExcepSean
Nov 8 at 18:54
@TheImpaler, the old style comma separated joins are still in the SQL standard, can't really be removed... But don't use them when writing new code!
– jarlh
Nov 8 at 20:29
You can, but not on the same table without proper aliases (and you shouldn't be using implicit joins anyway, since explicit joins are a part of ANSI-SQL for almost 30 years now...)
– Zohar Peled
Nov 8 at 18:53
You can, but not on the same table without proper aliases (and you shouldn't be using implicit joins anyway, since explicit joins are a part of ANSI-SQL for almost 30 years now...)
– Zohar Peled
Nov 8 at 18:53
1
1
IMHO one shouldn't mix old comma-syntax joins with any other query that contains characters. :-)
– Shawn
Nov 8 at 18:53
IMHO one shouldn't mix old comma-syntax joins with any other query that contains characters. :-)
– Shawn
Nov 8 at 18:53
Just a pedantic comment: some databases allow you to mix old & new style joins. It's confusing to me, and my take is they shouldn't be allowed. But they do.
– The Impaler
Nov 8 at 18:53
Just a pedantic comment: some databases allow you to mix old & new style joins. It's confusing to me, and my take is they shouldn't be allowed. But they do.
– The Impaler
Nov 8 at 18:53
Thanks for the feedback; answer updated.
– UnhandledExcepSean
Nov 8 at 18:54
Thanks for the feedback; answer updated.
– UnhandledExcepSean
Nov 8 at 18:54
@TheImpaler, the old style comma separated joins are still in the SQL standard, can't really be removed... But don't use them when writing new code!
– jarlh
Nov 8 at 20:29
@TheImpaler, the old style comma separated joins are still in the SQL standard, can't really be removed... But don't use them when writing new code!
– jarlh
Nov 8 at 20:29
add a comment |
up vote
1
down vote
FROM subjects, enrollments
There's your problem.
Change that to FROM subjects
- problem solved.
add a comment |
up vote
1
down vote
FROM subjects, enrollments
There's your problem.
Change that to FROM subjects
- problem solved.
add a comment |
up vote
1
down vote
up vote
1
down vote
FROM subjects, enrollments
There's your problem.
Change that to FROM subjects
- problem solved.
FROM subjects, enrollments
There's your problem.
Change that to FROM subjects
- problem solved.
answered Nov 8 at 18:51
Zohar Peled
51.8k73172
51.8k73172
add a comment |
add a comment |
up vote
1
down vote
I think the query you want is:
SELECT s.neptuncode, s.subjectname, MAX(e.examdate) as "examdate"
FROM subjects s JOIN
enrollments e
ON e.subject = s.subject_ID
GROUP BY s.neptuncode, s.subjectname
HAVING COUNT(*) = 1
ORDER BY s.neptuncode, s.subjectname;
This returns the exam date for subjects that have only one enrollee.
Notes:
Never use commas in theFROM
clause. Always use proper explicitJOIN
syntax.- A
LEFT JOIN
is not needed. YourHAVING
clause suggests that you want exactly one match. - You should be using
GROUP BY
; theHAVING
presupposes that you want to aggregate. - There is no need to include the exam date in the
ORDER BY
, because there is only one row per neptun code and subject.
Thanks a lot I got the idea. But how can I list the codes(neptuncode) and names of all subjects(subjectname) in case of those subjects, for which any of the students registered for the first time, list exam date for this condition.
– Emil Bədrəddinli
Nov 8 at 19:14
2
@EmilBədrəddinli . . . You should ask a new question as a new question. Along the way, it is good practice to accept an answer for this question.
– Gordon Linoff
Nov 8 at 19:33
add a comment |
up vote
1
down vote
I think the query you want is:
SELECT s.neptuncode, s.subjectname, MAX(e.examdate) as "examdate"
FROM subjects s JOIN
enrollments e
ON e.subject = s.subject_ID
GROUP BY s.neptuncode, s.subjectname
HAVING COUNT(*) = 1
ORDER BY s.neptuncode, s.subjectname;
This returns the exam date for subjects that have only one enrollee.
Notes:
Never use commas in theFROM
clause. Always use proper explicitJOIN
syntax.- A
LEFT JOIN
is not needed. YourHAVING
clause suggests that you want exactly one match. - You should be using
GROUP BY
; theHAVING
presupposes that you want to aggregate. - There is no need to include the exam date in the
ORDER BY
, because there is only one row per neptun code and subject.
Thanks a lot I got the idea. But how can I list the codes(neptuncode) and names of all subjects(subjectname) in case of those subjects, for which any of the students registered for the first time, list exam date for this condition.
– Emil Bədrəddinli
Nov 8 at 19:14
2
@EmilBədrəddinli . . . You should ask a new question as a new question. Along the way, it is good practice to accept an answer for this question.
– Gordon Linoff
Nov 8 at 19:33
add a comment |
up vote
1
down vote
up vote
1
down vote
I think the query you want is:
SELECT s.neptuncode, s.subjectname, MAX(e.examdate) as "examdate"
FROM subjects s JOIN
enrollments e
ON e.subject = s.subject_ID
GROUP BY s.neptuncode, s.subjectname
HAVING COUNT(*) = 1
ORDER BY s.neptuncode, s.subjectname;
This returns the exam date for subjects that have only one enrollee.
Notes:
Never use commas in theFROM
clause. Always use proper explicitJOIN
syntax.- A
LEFT JOIN
is not needed. YourHAVING
clause suggests that you want exactly one match. - You should be using
GROUP BY
; theHAVING
presupposes that you want to aggregate. - There is no need to include the exam date in the
ORDER BY
, because there is only one row per neptun code and subject.
I think the query you want is:
SELECT s.neptuncode, s.subjectname, MAX(e.examdate) as "examdate"
FROM subjects s JOIN
enrollments e
ON e.subject = s.subject_ID
GROUP BY s.neptuncode, s.subjectname
HAVING COUNT(*) = 1
ORDER BY s.neptuncode, s.subjectname;
This returns the exam date for subjects that have only one enrollee.
Notes:
Never use commas in theFROM
clause. Always use proper explicitJOIN
syntax.- A
LEFT JOIN
is not needed. YourHAVING
clause suggests that you want exactly one match. - You should be using
GROUP BY
; theHAVING
presupposes that you want to aggregate. - There is no need to include the exam date in the
ORDER BY
, because there is only one row per neptun code and subject.
answered Nov 8 at 18:54
Gordon Linoff
750k34286393
750k34286393
Thanks a lot I got the idea. But how can I list the codes(neptuncode) and names of all subjects(subjectname) in case of those subjects, for which any of the students registered for the first time, list exam date for this condition.
– Emil Bədrəddinli
Nov 8 at 19:14
2
@EmilBədrəddinli . . . You should ask a new question as a new question. Along the way, it is good practice to accept an answer for this question.
– Gordon Linoff
Nov 8 at 19:33
add a comment |
Thanks a lot I got the idea. But how can I list the codes(neptuncode) and names of all subjects(subjectname) in case of those subjects, for which any of the students registered for the first time, list exam date for this condition.
– Emil Bədrəddinli
Nov 8 at 19:14
2
@EmilBədrəddinli . . . You should ask a new question as a new question. Along the way, it is good practice to accept an answer for this question.
– Gordon Linoff
Nov 8 at 19:33
Thanks a lot I got the idea. But how can I list the codes(neptuncode) and names of all subjects(subjectname) in case of those subjects, for which any of the students registered for the first time, list exam date for this condition.
– Emil Bədrəddinli
Nov 8 at 19:14
Thanks a lot I got the idea. But how can I list the codes(neptuncode) and names of all subjects(subjectname) in case of those subjects, for which any of the students registered for the first time, list exam date for this condition.
– Emil Bədrəddinli
Nov 8 at 19:14
2
2
@EmilBədrəddinli . . . You should ask a new question as a new question. Along the way, it is good practice to accept an answer for this question.
– Gordon Linoff
Nov 8 at 19:33
@EmilBədrəddinli . . . You should ask a new question as a new question. Along the way, it is good practice to accept an answer for this question.
– Gordon Linoff
Nov 8 at 19:33
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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%2f53214302%2finvalid-identifier-when-using-left-outer-join-in-sql%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
You should explain what you want to do, given that your query has multiple errors. A database tag is also helpful.
– Gordon Linoff
Nov 8 at 18:56
enrollments LEFT OUTER JOIN enrollments ...
– jarlh
Nov 8 at 20:28
Bad habits to kick : using old-style JOINs - that old-style comma-separated list of tables style was replaced with the proper ANSI
JOIN
syntax in the ANSI-92 SQL Standard (more than 25 years ago) and its use is discouraged– marc_s
Nov 8 at 21:22