I am unable to fix this issue MySQL - mysql

I have recently started MySQL and I got the MySQL Workbench and I am making a table.
But there is a section where it has the red cross and I do not know what is wrong with my code. I have tried changing the syntax but the error does not go away. Can someone please help me?
CREATE DATABASE form_acceptance;
CREATE TABLE form_acceptance (
PersonID int,
Player_Name varchar(255),
Countries varchar(255),
Username varchar(255),
Level_and_rank varchar(255),
Max_BR varchar(255)
);
INSERT INTO form_acceptance (SayByeBye_exe, SayByeBye_exe, US, '^GYMP^SayByeBye_exe', '12_Luitenant', '4.7');
SELECT PersonID, Player_Name, Countries, Username, Level_and_rank, Max_BR
This is my code so far. Except where it says INSERT INTO form_acceptance it says it is wrong and I have no idea why.
enter image description here
Thanks

It appears that you roughly got the insert logic backwards, providing the target column names in the select, and the literal values in the insert clause. Try reversing this order:
INSERT INTO form_acceptance (PersonID, Player_Name, Countries, Username, Level_and_rank, Max_BR)
SELECT 'SayByeBye_exe', 'SayByeBye_exe', 'US', '^GYMP^SayByeBye_exe', '12_Luitenant', '4.7';
You could also just use a VALUES clause here:
INSERT INTO form_acceptance (PersonID, Player_Name, Countries, Username, Level_and_rank, Max_BR)
VALUES
('SayByeBye_exe', 'SayByeBye_exe', 'US', '^GYMP^SayByeBye_exe', '12_Luitenant', '4.7');

You just need to reverse your syntax -
INSERT INTO form_acceptance (PersonID, Player_Name, Countries, Username, Level_and_rank, Max_BR)
SELECT Some_integer_value, 'SayByeBye_exe', 'US', '^GYMP^SayByeBye_exe', '12_Luitenant', '4.7';

Related

The function IN not working in SQL for a table that I created

I've created the following table. I'm trying to use the 'IN' function within a 'Where' statement so as to get the desired result however it is not working. Getting a blanked result. Any insight on the same would be appreciated.
CREATE TABLE student (
student_id int PRIMARY KEY,
name VARCHAR(20),
age int,
subject VARCHAR(20)
);
INSERT INTO student VALUES(1, 'Shyam', 23, 'History')
INSERT INTO student VALUES(2, 'Jack', 21, 'Biology')
INSERT INTO student VALUES(3, 'Reba', 32, 'Chemistry')
Insert Into student VALUES(4, 'Sukanya', 21, 'Pillai')
select
from student
where subject in ('Chemistry', 'Biology');
I ran the above query, however I'm getting the result as blank even though it should show me the columns in which the same is present.
I've tried to run this multiple times. However, I'm getting no result whatsoever. There's no error either. It's just a blank output. I'm not sure why.
Try writing your code this way:
select * from student
where subject IN ('Chemistry','Biology');

Syntax Error in CREATE TABLE Statement in MS Access

I have created a table called Customers with a CustomerID, Last Name, First Name, Address, and City, but when I tried to use the INSERT INTO to add data and ran the SQL Statement, it gives me an error: "Syntax error in CREATE TABLE statement". Below is the SQL Statement I have so far:
CREATE TABLE Customers
(
CustomerID int,
LastName varchar(50),
FirstName varchar(50),
Address varchar(50),
City varchar(50)
);
INSERT INTO (CustomerID, LastName, FirstName, Address, City)
VALUES ('10001', 'Smith', 'John', '1002 Danville Road', 'Louisville');
You are missing the table name from your INSERT statement:
INSERT INTO Customers (CustomerID, LastName, FirstName, Address, City)
VALUES ('10001', 'Smith', 'John', '1002 Danville Road', 'Louisville');
As to why you got an error pointing to your CREATE TABLE statement (which looks correct), my guess is that Access tried to connect the botched INSERT statement to the create in an effort to parse everything correctly.

How to get the higest number out of the table?

So I have a table of players which I created in sql:
CREATE TABLE Player(PlayerID varchar(10) PRIMARY KEY, level int, region varchar(2), name varchar(10));
And then with the following values:
INSERT INTO Player VALUES ('p001','20', 'eu','phatey');
INSERT INTO Player VALUES ('p002', '15', 'eu', 'hellowz');
INSERT INTO Player VALUES ('p003', '10', 'eu', '3xphhate');
Which I don't understand is how to make use of SUM in order to get the highest level of the players(Mostly because I am doing it wrong since I am pretty newbie with this) any suggestion?
select max(column_name) from table_name;
I hope it helps!

Inserting into an SQL database?

I know this sounds like a very basic question but i've been doing SQl for a little while now and only ever come across this once and its just blowing my mind.
I have a DB called stud with 6 columns.
sid , firstname,lastname ,title,dob , gender
"124084","Bobby" ,"Carpenter","Mr" ,"040774","m"
"129002","Robin" ,"Hart" ,"Ms" ,"160275","f"
"129275","Julia" ,"Foster" ,"Ms" ,"080575","f"
I'm trying to insert it in stud but am getting the
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
INSERT INTO stud ( "123969","Heather","Howard","Ms","111274","f"
"124084","Bobby","Carpenter","Mr","040774","m"
"129002","Robin","Hart","Ms","160275","f"
is this because the data doesnt have an extra comma after the sex part or?
Sorry for such a noob question but its just been one of them days.
you need to identify the rows
INSERT INTO stud (sid, firstname, lastname, title, dob, gender)
values ("123969","Heather","Howard","Ms","111274","f")
, ("124084","Bobby","Carpenter","Mr","040774","m")
, ("129002","Robin","Hart","Ms","160275","f")
You need to identify rows and use single quotes, not double. Double quotes interpreted not as strings, but as identifiers, such as table/column name.
INSERT INTO stud (sid, firstname, lastname, title, dob, gender)
values ('123969','Heather','Howard','Ms','111274','f')
, ('124084','Bobby','Carpenter','Mr','040774','m')
, ('129002','Robin','Hart','Ms','160275','f')

How to insert into a table from another table and from user input?

What I am trying to do is something like this
INSERT INTO BOOKS(borrower_name,isbn) VALUES("Jane",SELECT isbn from TABLE...);
This is wrong obviously. But I am trying to get something that would work the way this would (if it did).
You were very close
INSERT INTO books (borrower_name, isbn)
SELECT 'Jane', isbn
FROM table_name
-- WHERE id = ?
You might want to limit number of rows coming from table_name by using WHERE clause and proper condition(s)
Here is SQLFiddle demo
More over if you meant to return from SELECT only a scalar value (just one ISBN) then you were correct in the first place and could've used syntax showed in your question
INSERT INTO books (borrower_name,isbn)
VALUES ('Jane',
(
SELECT isbn
FROM table_name
WHERE id = 1
));
Here is SQLFiddle demo
What you were doing is also right, u only missed () for select statement:
INSERT INTO BOOKS(borrower_name,isbn) VALUES("Jane",SELECT isbn from TABLE...);
should be modified to:
INSERT INTO BOOKS(borrower_name,isbn) VALUES("Jane",(SELECT isbn from TABLE...));
and it will work perfectly fine!! here is the SQLFiddle demo
INSERT INTO BOOKS(borrower_name,isbn)
SELECT 'Jane', isbn from TABLE
Check This My Answer...
Example:
I have two table Employee and Client
Insert into Employee (name, city) values((select name from client where id=2),'example');
follow this method