Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6776305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:00:43+00:00 2026-05-26T16:00:43+00:00

I am creating a view for a database for an assignment, i keep getting

  • 0

I am creating a view for a database for an assignment,

i keep getting this error in my code though.

CREATE VIEW Rental_View

SELECT Mo.Movie_ID, copy_id, mo.Movie_Name, format_name
FROM Movies AS mo JOIN copies AS co
ON mo.Movie_ID = co.movie_id  
JOIN format AS fo
ON co.Format_id = fo.format_id

SELECT c.customer_id, rental_ID, DATEDIFF (day, rental_date, return_date) AS  rental_duration' , c.first_name + ' ' + c.last_name AS customer_name
FROM Customers AS c INNER JOIN rentals AS r
ON c.customer_ID = r.customer_ID

In the first SELECT statement it is underlined red and i get the error

“Incorrect syntax near the keyword ‘SELECT’.”

i literally have no idea how to correct this as i am fairly new to SQL, any help would be much appreciated.

thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:00:43+00:00Added an answer on May 26, 2026 at 4:00 pm

    You need the AS keyword:

    CREATE VIEW Rental_View   AS            --- <------ AS needed here
    
    SELECT mo.Movie_ID                     --- mo, not Mo
         , co.copy_id                      --- play safe and declare which table 
         , mo.Movie_Name
         , fo.format_name                  --- are these two columns from
    FROM Movies AS mo JOIN copies AS co
    ON mo.Movie_ID = co.movie_id  
    JOIN format AS fo
    ON co.Format_id = fo.format_id  
    ;                                     --- add a ; if you want to
                                          --- run multiple statements
    

    If you want to combine the two SELECT in one, you need to JOIN the tables from both, with something like this:

    CREATE VIEW Rental_View   AS           
    
    SELECT mo.Movie_ID                     
         , co.copy_id                      
         , mo.Movie_Name
         , fo.format_name                  
         , c.customer_id
         , rental_ID
         , DATEDIFF (day, rental_date, return_date) AS rental_duration 
         , c.first_name + ' ' + c.last_name AS customer_name
    FROM Movies AS mo 
      JOIN copies AS co
        ON mo.Movie_ID = co.movie_id  
      JOIN format AS fo
        ON co.Format_id = fo.format_id  
    
      JOIN rentals AS r
        ON r.movie_id = mo.Movie_id        --- just a guess, you have to write this
      JOIN Customers AS c 
        ON c.customer_ID = r.customer_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code to create VIEW in mysql database which is working fine
I'm doing this tutorial: http://www.phpeveryday.com/articles/Zend-Framework-Database-Creating-Input-Form-P494.html We are building a simple input form using POST
I'm creating a VIEW of a database in smarty . I am little bit
I've a massive problem creating a view in mySQL: Table A in database DB1:
I'm trying to load text from sqlite database in detailed view and I'm getting
I am using ASP.NET MVC 1.0. I am creating a view to Create a
When creating a view and setting group by value some field, it groups only
Can rails handle creating a view without a controller? For example, let say I
I am creating an SQL view for a file that strips out the spaces
In MVVM pattern I don't want to think about the view while creating the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.