Featured Worklog

Price Search



PC Apex Sponsor


PC Apex Sponsors



PC Apex RSS Feeds

RSS Feed for PC Apex Reviews & ArticlesRSS Feed for PC Apex PC Modding WorklogsRSS Feed for the PC Apex Daily DisturbanceRSS Feed for the latest PC Apex Site NewsRSS Feed for PC Apex Affiliate and Web NewsRSS Feed for PC Apex Deals and Steals

Go Back   Apex Community Forums // Other Forums // Designers Corner // Coding / Scripting / Programming

Coding / Scripting / Programming Discussions on all manner of coding and scripting.

Reply
 
LinkBack Thread Tools Display Modes
Old 11-November-05, 06:21 PM   #1 (permalink)
Apex Tech Fanatic
Demon Made's Avatar
Default Sql

Dose anyone know SQL? IÂ’m taking a SQL concepts class using Microsoft Access and I canÂ’t for the life of me figure out one of the problems on this assignment. Any help would be appreciated.

(6 points) For all students, list the student name in the first column. In the second column display 'Yes' if the student has enrolled in any course. Display 'No' in the second column if the student has not enrolled in any courses. Sort the results by student name. NOTE: It is possible for a student to have a NULL GPA even if they have enrolled in a course (they may not have completed the course yet!).

Here is the Database and discription this problem uses.
Demon Made is offline     Reply With Quote
Old 11-November-05, 10:33 PM   #2 (permalink)
Apex Tech Fanatic
Demon Made's Avatar
Default

Anyone? iv been messing with this for over a day and its due in about an hour...yikes.
Demon Made is offline     Reply With Quote
Old 12-November-05, 01:52 AM   #3 (permalink)
A George Orwell fan...sorta
godfoot's Avatar
Default

I can come up with the query if given a little time. If you don't need it before the weekend is over.
godfoot is offline     Reply With Quote
Old 12-November-05, 09:48 AM   #4 (permalink)
Apex Tech Fanatic
Demon Made's Avatar
Default

i came up with this('.' are just formating place holders):

SELECT stuname, (SELECT 'Yes'
.........................................FROM entroll
.....................................WHERE EXISTS (SELECT stuid
.................................................. .......................FROM enroll
.................................................. ...................WHERE enroll.stuid = student.stuid))

....................................UNION

.................................(SELECT 'No'
......................................FROM entroll
..................................WHERE NOT EXISTS (SELECT stuid
.................................................. .............................FROM enroll
.................................................. .........................WHERE enroll.stuid = student.stuid))
FROM student
ORDER BY stuname;


but it dosnt work. depending on how i do the parenthases around the sub-querie it gives me a few different error messages. I turned the assignment in, but if i could still get some help with it i could turn the on problem in late.

Thanks godfoot

Last edited by Demon Made; 12-November-05 at 09:55 AM..
Demon Made is offline     Reply With Quote
Old 13-November-05, 12:03 AM   #5 (permalink)
A George Orwell fan...sorta
godfoot's Avatar
Default

Quote:
Originally Posted by Demon Made
i came up with this('.' are just formating place holders):

SELECT stuname, (SELECT 'Yes'
.........................................FROM entroll
.....................................WHERE EXISTS (SELECT stuid
.................................................. .......................FROM enroll
.................................................. ...................WHERE enroll.stuid = student.stuid))

....................................UNION

.................................(SELECT 'No'
......................................FROM entroll
..................................WHERE NOT EXISTS (SELECT stuid
.................................................. .............................FROM enroll
.................................................. .........................WHERE enroll.stuid = student.stuid))
FROM student
ORDER BY stuname;


but it dosnt work. depending on how i do the parenthases around the sub-querie it gives me a few different error messages. I turned the assignment in, but if i could still get some help with it i could turn the on problem in late.

Thanks godfoot

Well, I admit that my SQL knowledge is limited to what I have learned in the last few months, but what you have looks pretty close except for the text in red having a typo. I am not sure either whether that typo was in the query that you submitted. Only other thing(s) I could think of are potential missing semicolons.
godfoot is offline     Reply With Quote
Old 13-November-05, 06:06 PM   #6 (permalink)
Apex Tech Fanatic
Demon Made's Avatar
Default

when i run that query i get this error:

"Query input must contain at least one table or query."

I have no idea what this means. Oh, and yeah that misspell was in the query but apparently the assebler didnt get that far in running it to notice.

Last edited by Demon Made; 14-November-05 at 06:27 PM..
Demon Made is offline     Reply With Quote
Old 13-November-05, 07:43 PM   #7 (permalink)
A George Orwell fan...sorta
godfoot's Avatar
Default

Quote:
Originally Posted by Demon Made
when i run that query i get this error: "

Query input must contain at least one table or query."

I have no idea what this means. Oh, and yeah that misspell was in the query but apparently the assebler didnt get that far in running it to notice.

If the table you are trying to query was misspelled, you will always get that error as it cannot find the table it is looking for since it is misspelled. Have you tried rerunning the query with the proper spelling?
godfoot is offline     Reply With Quote
Old 14-November-05, 06:27 PM   #8 (permalink)
Apex Tech Fanatic
Demon Made's Avatar
Default

yeah i have and i quoted the error. its the same error as before when the table was misspelled
Demon Made is offline     Reply With Quote
Old 14-November-05, 09:11 PM   #9 (permalink)
A George Orwell fan...sorta
godfoot's Avatar
Default

I'm not sure what to tell you then, as I said my SQL knowledge is limited... sorry.
godfoot is offline     Reply With Quote
Old 14-November-05, 09:21 PM   #10 (permalink)
Pimp PHP Pro
vladimir's Avatar
Default

4 queries within one...damn
vladimir is offline     Reply With Quote
Old 14-November-05, 10:33 PM   #11 (permalink)
Apex Tech Fanatic
Demon Made's Avatar
Default

i appreciate the help anyway godfoot.

Quote:
Originally Posted by CLowN
4 queries within one...damn

yeah i know, and this is the SQL Concepts (begining SQL) class. all we do is cover the SELECT statment.
Demon Made is offline     Reply With Quote
Old 15-November-05, 09:28 AM   #12 (permalink)
'Da Doctor of Funk
FunkyFresh's Avatar
Default

Here's one that works, but it may use some things the teacher hasn't covered yet (they don't often like when you get too far ahead of 'em ).
Code:
SELECT StuName, (IIF(SUM(Enroll.StuId) > 0, 'Yes', 'No')) AS Enrolled
FROM Student LEFT JOIN Enroll ON Student.StuId = Enroll.StuId
GROUP BY StuName
ORDER BY StuName;
In your query, it was giving you that error only because of the parenthases. Here it is with only the parenthases changed (Now the UNION statement is inside the parenthases). If you run this:
Code:
SELECT stuname, ((SELECT 'Yes'
FROM enroll
WHERE EXISTS (SELECT stuid
     FROM enroll
     WHERE enroll.stuid = student.stuid)

UNION

(SELECT 'No'
FROM enroll
WHERE NOT EXISTS (SELECT stuid
     FROM enroll
     WHERE enroll.stuid = student.stuid)))
FROM student
ORDER BY stuname;
then it'll give you a different error message, "Operation is not allowed in subqueries". I think it's talking about the "EXISTS" operation. So if you use the modified version below that takes it out of a subquery, that would work.
Code:
SELECT StuName, 'Yes' AS Enrolled
FROM Student
WHERE EXISTS (SELECT StuId
     FROM Enroll
     WHERE Enroll.StuId = student.StuId)

UNION ALL

SELECT StuName, 'No' AS Enrolled
FROM Student
WHERE NOT EXISTS (SELECT StuId
     FROM Enroll
     WHERE Enroll.StuId = Student.StuId)

ORDER BY StuName;
And yes, the "ORDER BY" works for the whole statement, even though you'd think it'd only work for the second one. *shrug*

Note: I used "UNION ALL" in the last query instead of just plain "UNION", since it'll run faster for large queries. "UNION" attempts to eliminate any duplicate rows. But since you know there are no duplicates (aren't any No's in the first query or Yes's in the second query), "UNION ALL" will work the same and run faster.

Last edited by FunkyFresh; 15-November-05 at 09:34 AM..
FunkyFresh is offline     Reply With Quote
Old 01-December-05, 11:18 PM   #13 (permalink)
The Green Gator
DavidVaini's Avatar
Default

Quote:
Originally Posted by FunkyFresh
And yes, the "ORDER BY" works for the whole statement, even though you'd think it'd only work for the second one. *shrug*

Note: I used "UNION ALL" in the last query instead of just plain "UNION", since it'll run faster for large queries. "UNION" attempts to eliminate any duplicate rows. But since you know there are no duplicates (aren't any No's in the first query or Yes's in the second query), "UNION ALL" will work the same and run faster.

Good idea on the UNION ALL when I was working on a database, I was looking for something a little faster, and this would of helped me out greatly.
DavidVaini is offline     Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:55 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright PCApex.com, GameApex.com, ForumApex.com 2001 - 2008
Advertisements

Page generated in 0.22907 seconds with 8 queries