What is wrong with my MySQL syntax

Posted on 2011-05-07
Last Modified: 2012-08-14
where am I going wrong with the Syntax?
$sql = "INSERT INTO iowa (universityName) VALUES
('Des Moines College') BETWEEN universityName='Cornell College' AND universityName='Divine Word College'";

Open in new window

I know everything is spelled right, there must be a logic error
Question by:NewWebDesigner
    LVL 11

    Expert Comment

    That 'BETWEEN' syntax is incorrect. You should split it into three separate inserts or insert using a SELECT:
    INSERT INTO iowa (universityName) VALUES ('Des Moines College');
    INSERT INTO iowa (universityName) VALUES ('Cornell College');
    INSERT INTO iowa (universityName) VALUES ('Divine Word College');

    Open in new window

    LVL 33

    Accepted Solution

    If you want to just insert Des Moines then lose the Between.

    You can't specify that a particular record is inserted in a particular position in a table, and you shouldn't need to anyway.
    LVL 15

    Expert Comment

    by:Jagadishwor Dulal
    INSERT INTO iowas (universityName) VALUES ('Cornell College'), ('Divine Word College');

    Open in new window

    LVL 107

    Assisted Solution

    by:Ray Paseur
    Have you got any nearby community colleges that teach the basics of SQL?  If so, sign up right now.  If not, this book might help you get started.  It will not make you a pro, but it will get you some foundation and will help you get "from zero to sixty" in the query language.

    HTH, ~Ray
    LVL 82

    Assisted Solution

    by:Dave Baldwin
    None of the SQL databases preserve any particular order to the rows except that defined by an ORDER BY expression in a SELECT statement.  BETWEEN doesn't work in an INSERT statement.  It is only useful to tell whether something is in a range.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now