How to create a generic View for different Models?

How to create a view in SQL based on multiple tables?

  • I'm working on a school assignment. Its basically a database on students. I have following two tables namely: EXAM_DETAILS and EXAM_APPEARS, The Fields for EXAM_DETAILS are (exam_code, total_marks, exam_date) The Fields for EXAM_APPEARS are(roll_no, exam_code, marks) Now, I've to create a view showing details of:-“roll_no, exam_name, marks, total_marks, exam_date”, for students having marks in the range 40 to 60. Can u please tell me how to create a view that comprises of fields from more than one table. A heart-full thanx +2points guaranteed!

  • Answer:

    It will be something like this though I take no responsibility if there is an error in there. CREATE VIEW NEW_VIEW AS SELECT A.roll_no, exam_name, --Where does this even come from? A.marks, D.total_marks, D.exam_date FROM EXAM_APPEARS A JOIN EXAM_DETAILS D ON A.exam_code = D.exam_code WHERE A.marks >= 40 AND A.marks <= 60

James Hahn at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

You will want to use a JOIN to accomplish your task.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.