Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
A MySQL table called SQ was created as follows,
CREATE TABLE SQ(
SQno INT PRIMARY KEY,
Question VARCHAR(100)
);
After I was trying to enter data to that table like this,
INSERT INTO SQ (SQno, Question) VALUES(
(1,'What primary school did you attend?'),
(2,'In what town or city did your parents meet?'),
(3,'In what city or town was your first job?'),
);
But there was an error occurs, and shows as this,
ERROR 1136 (21S01): Column count doesn't match value count at row 1
So, please help me to resolve this error?
You need to get rid of the outer set of parentheses; each row should have parentheses around it but not also all the rows:
INSERT INTO SQ (SQno, Question) VALUES
(1,'What primary school did you attend?'),
(2,'In what town or city did your parents meet?'),
(3,'In what city or town was your first job?')
;
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Here is the statement I have now:
INSERT INTO jobs
SELECT *
FROM proposals
JOIN commissions
ON proposals.commission_id = commissions.job_id
WHERE proposals.proposal_id = '123'
It's working fine but is creating some primary key conflicts. So, what I would like to do when the new row is entered, is this:
new primary key + commissions table data + proposals table data
Any ideas?
then if you have auto increment pk , do this :
INSERT INTO jobs ( [list of columns except the auto increment column])
SELECT ( [list of columns accordingly])
FROM proposals
JOIN commissions
ON proposals.commission_id = commissions.job_id
WHERE proposals.proposal_id = '123'
Like p.Salmon said in the comments, I would add a new column to the jobs table
ALTER TABLE Jobs add autoid INT(10)AUTO_INCREMENT PRIMARY KEY;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
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 'DECIMAL(3, 2)' at line 1
CREATE TABLE student (
stud_id INT,
name_f VARCHAR(20),
email VARCHAR(20),
PRIMARY KEY(stud_id)
);
DESCRIBE student;
DROP TABLE student;
ALTER TABLE student ADD DECIMAL(3, 2);
my full code is those.
You are dropping the table before trying to add the new column. Also, you need to give the new column a name.
This makes more sense:
CREATE TABLE student (
stud_id INT,
name_f VARCHAR(20),
email VARCHAR(20),
PRIMARY KEY(stud_id)
);
ALTER TABLE student ADD newcol DECIMAL(3, 2);
DROP TABLE student; drops the table from the db so you can't manipulate it again.
Also, your alter statement does not include the column name.
You have dropped the table using the DROP TABLE student...
Therefore you can not do anything to it since it's deleted after dropping it
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I created a table called 'parent'
Create table parent (p_id int(11) primary key, p_name varchar(255));
And another table called "child" with foreign key referenced to the parent Id table as below
Create table child (ch_id int(11), primary key, ch_name varchar(255), ch_fk int(11) references parent(p_id));
Both tables were created successfully and I add some data in both of them. But when I tried to get the data of a parent and his children it renders all available data of the child table
My query is as below.
Select * from parent , child where p_id=2
You want to join the tables explicitly - otherwise you end up with a cartesian product, where all rows on one side are joined to all rows on the other side.
I suspect what you want is:
SELECT * FROM parent p INNER JOIN child c ON p.p_id = c_ch_fk WHERE p_id=2
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a table with 4 columns:
id1 int
id2 text or varChar
type
timestamp
The primary key is (id1,id2,type)
and I want to change to (id2,id1,type) .
What is the difference in performance will be?Maybe it will be similar to the keys on the performance?
Don't add such kind primary key, use a long/int value for primary key, or a sequence if your database has one.
And, if you want to make a column or a combination of columns to be unique, just mark it or the combination of them as unique.
And also, for columns which are not primary key, you can also add index key to it or them, if need to.
You'll have two indexes like:
id1, id2, type - together(so you must use all three column in WHERE clause).
Also
1 case(id1,id2,type) - you can use in WHERE separate id1.
2 case(id2,id1,type) - you can use in WHERE separate id2.
But it's not really good practice to use several column as primary key.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Insert a value in a column name e-mail then it display all emails seperated by comma. This email is save at different time but for same id.
Is it possible then how?
You can use GROUP_CONCAT to show the comma separated records that belong to same group,be aware of that fact GROUP_CONCAT has a default limit of 1024 characters to concat but it can be increased as mentioned in docs
CREATE TABLE Table1
(id INT ,`test` varchar(25))
;
INSERT INTO Table1
(id,`test`)
VALUES
(1,'test#test.com'),
(1,'test#test.com'),
(1,'test#test.com'),
(2,'test2#test.com'),
(2,'test2#test.com'),
(2,'test2#test.com')
;
SELECT id, GROUP_CONCAT(test) emails
FROM
Table1 GROUP BY id
Fiddle Demo