create table WEL
(
pipe_type varchar(30),date DATE
)
insert into WEL values(H.T.NO.2,....,....)
getting error multi-part identifier h.t.no.2 could not be bound and 2 is a incorrect syntax
is there any problem with varchar or any other way to insert H.T.NO.2 into table
For Character Type Data Types we must give single quotes
For inserting a single record we have two options
First one
insert into WEL values('H.T.NO.2','2013-07-07');
Second one
insert into WEL(pipe_type,date) values('H.T.NO.2','2013-07-07');
This will helpful when default value is given.For example
If i give default value for date like '2000-02-02'.Then we will write query like this
insert into WEL(pipe_type) values('H.T.NO.2');
Then system takes default value which you give(like 2000-02-02 ) for that one.
Importance of Delimiter(;):
I observe that you didn't give ";" .If so, The database checks for another query.So for one query its not an important,But for multiple its very Important.
You have to enclose varchar and date values in single quotes:
insert into WEL values('H.T.NO.2', '2013-12-31')
Use the following format to insert the string into database:
insert into WEL values('H.T.NO.2',....,....);
Always enclose the string with Quota mark.
As given in other answers you need to put values in single qoutes.
The error message
multi-part identifier h.t.no.2 could not be bound
is coming because MySQL is reading h.t.no.2 as a column name rather than a string value
Related
I have created a database in MySQL and am trying to insert values into a table called Artist but keep receiving the SQL error in the title. This is the query I am trying to execute
insert Artist (ArtistId, name, genre, social media, G_id)
Values ('911', 'Alessandro Torlonia', 'Ancient Greek/Roman', '', '734')
I have also tried executing INSERT INTO before my table name and have run out of ideas to make it work. Do I need to update MySQL workbench or any other suggestions?
The standard insert syntax goes like:
insert into Artist (ArtistId, name, genre, social_media, G_id)
values (911, 'Alessandro Torlonia', 'Ancient Greek/Roman', NULL, 734)
Notes:
presumably, ArtistId and G_id are of a numeric datatype (such as INT), not strings (VARCHAR or the-like); if so, I would recommend not surrounding the values with single quotes. Using strings won't raise errors (the database handles the conversion for you under the hood) but it is good practice to use the proper datatype
social media probably needs an underscore in between; or, if you do have a space in the column name, you need to surround the column name with backticks. Note that I assigned a NULL value to instead of the empty string; this is usually the preferred way to represent the absence of data (and it is valid for all datatypes, unlike the empty string, that only string-like datatypes support)
I'm trying to get results when both tables have the same machine number and there are entries that have the same number in both tables.
Here is what I've tried:
SELECT fehler.*,
'maschine.Maschinen-Typ',
maschine.Auftragsnummer,
maschine.Kunde,
maschine.Liefertermin_Soll
FROM fehler
JOIN maschine
ON ltrim(rtrim('maschine.Maschinen-Nr')) = ltrim(rtrim(fehler.Maschinen_Nr))
The field I'm joining on is a varchar in both cases. I tried without trims but still returns empty
I'm using MariaDB (if that's important).
ON ltrim(rtrim('maschine.Maschinen-Nr')) = ltrim(rtrim(fehler.Maschinen_Nr)) seems wrong...
Is fehler.Maschinen_Nr really the string 'maschine.Maschinen-Nr'?
SELECT fehler.*, `maschine.Maschinen-Typ`, maschine.Auftragsnummer, maschine.Kunde, maschine.Liefertermin_Soll
FROM fehler
JOIN maschine
ON ltrim(rtrim(`maschine.Maschinen-Nr`)) = ltrim(rtrim(`fehler.Maschinen_Nr`))
Last line compared a string to a number. This should be doing it.
Also, use the backtick to reference the column names.
The single quotes are string delimiters. You are comparing fehler.Maschinen_Nr with the string 'maschine.Maschinen-Nr'. In standard SQL you would use double quotes for names (and I think MariaDB allows this, too, certain settings provided). In MariaDB the commonly used name qualifier is the backtick:
SELECT fehler.*,
`maschine.Maschinen-Typ`,
maschine.Auftragsnummer,
maschine.Kunde,
maschine.Liefertermin_Soll
FROM fehler
JOIN maschine
ON trim(`maschine.Maschinen-Nr`) = trim(fehler.Maschinen_Nr)
(It would be better of course not to use names with a minus sign or other characters that force you to use name delimiters in the first place.)
As you see, you can use TRIM instead of LTRIM and RTRIM. It would be better, though, not to allow space at the beginning or end when inserting data. Then you wouldn't have to remove them in every query.
Moreover, it seems Maschinen_Nr should be primary key for the table maschine and naturally a foreign key then in table fehler. That would make sure fehler doesn't contain any Maschinen_Nr that not exists exactly so in maschine.
To avoid this problems in future, the convention for DB's is snake case(lowercase_lowercase).
Besides that, posting your DB schema would be really helpfull since i dont guess your data structures.
(For friendly development, is usefull that variables, tables and columns should be written in english)
So with this, what is the error that you get, because if table "maschine" has a column named "Maschinen-Nr" and table "fehler" has a column named "Maschinen_Nr" and the fields match each other, it should be correct
be careful with Maschinen-Nr and Maschinen_Nr. they have - and _ on purpose?
a very blind solution because you dont really tell what is your problem or even your schema is:
SELECT table1Alias.*, table2Alias.column_name, table2Alias.column_name
FROM table1 [table1Alias]
JOIN table2 [table2Alias]
ON ltrim(rtrim(table1Alias.matching_column)) = ltrim(rtrim(table2Alias.matching_column))
where matching_columns are respectively PK and FK or if the data matches both columns [] are optional and if not given, will be consider table_name
Whenever I tried to save my table using double data type this error appears please help I'm a newbie.
So your answer depends upon how you want to add double value in MYSQL.
If you want to query MYSQL through SQL then you should do the query using decimal value in your query instead of a comma.
a query should be like this...
INSERT INTO `comment` ( `no_of_comments` , `newField` ) VALUES (12,23.5)
Here newField is the double type and this query works fine.
And if you want to insert the default Decimal value in MYSQL database using PHPMYADMIN portal then you should add double value using the comma for decimal as...
Don't forget that you add comma just for defining the length of the decimal part, You add value in a proper double format for defining the value of the field.
There might have issue in Table Structure.
You have to Set Double Datatype with Length,Values Format.
Trying to run this query -
INSERT INTO rmedvedeva993#gmail.com (url,unix)
VALUES (#https://youtu.be/xXsuqrhD8pw,#1500152563.66077);
after reading about this issue tried wrapping database like this- rmedvedeva993#gmail.com
getting an error:
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 '://youtu.be/xXsuqrhD8pw,#1500152563.66077)' at line 1
not quite sure what's the issue here,
P.S.: my columns are formated as char(255)
`
#hhttps://youtu.be/xXsuqrhD8pw and #1500152563.66077 aren't valid.
Neither is an email address as the name of a table. If you MUST use an email address as a table name, enclose it in backticks. But think long and hard about why you're doing that, then don't do it.
You probably want VALUES ('https://youtu.be/xXsuqrhD8pw',1500152563.66077); .
The # symbol in MySQL's dialect of structured query language denotes a user-defined variable. So you could have this:
#url := 'https://youtu.be/xXsuqrhD8pw';
#ts := 1500152563.66077;
INSERT INTO table (url,unix) VALUES (#url,#ts);
You need to quote your strings (whether char(xx), varchar(xx), or any other type which is represented as a string); and, when the names of your tables are not just letters and numbers, you have to quote them with the backtick quote: `. You most probably don't won't either the # symbol.
INSERT INTO `rmedvedeva993#gmail.com` (url,unix)
VALUES ('https://youtu.be/xXsuqrhD8pw','1500152563.66077');
Side Note: Is your table really named rmedvedeva993#gmail.com? Can you post your table definitions (use SHOW CREATE TABLE table_name).
I'm creating a log table which logs actions that affect the database, and I store the sql statements in a field called details.
Below is an example query where I try to insert a row into my log table but I run into problems with the details part, as I am inserting a query into the field and mysql interprets it as part of the actual query and errors
INSERT INTO `user_log` SET `log_dts`='2012-05-28 15:07:19', `user_id`='4', `details`='UPDATE `property` SET `timedeleted` = '2012-05-28 15:07:19' WHERE `propertyid` IN (1594930)'
How is it best to handle this?
Thanks.
edit: to add, the details field is a text field in the mysql db.
You need to escape the quotation marks in your string.
See: http://dev.mysql.com/doc/refman/5.5/en/string-literals.html
You have to add an escape character to the "'", just replace all occurrences of ' in the query with \'.
mysql_real_escape_string - d'uh