Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Valid/Invalid Column Names


I'd like to present tabular data in HTML with the first row being the names of the columns in my database. However, I'd like them to be more presentable; for example 'I.P. Address' instead of 'ip_address'. I was wondering if a name like 'I.P. Address' could ever somehow be a valid column name or not.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Invalid Distinct Recordset Returned On An Indexed Column
I have a table with about 1.2 million records. I have an index set on a column.

For close to two years, this query has worked perfectly fine:

SELECT DISTINCT `Mgmt_Area` as thevalue, `Mgmt_Area` as valueid from qcdata ORDER BY thevalue

Note, this is a programmatically generated query based on some user selections. This query actually is used to create a listbox. The index has 62 separate values.

This query would usually return: Code:

Column Names
Is there something incorrect with the following query?

INSERT INTO
Faxes (Timestamp,Last Updated,Group,Flight,Poster,Origin,Destination,Title,TitleR,Comments,CommentsR,TTI,Private)
VALUES ( '2005-08-08 10:11:50.156', '2005-08-08 10:11:50.156', 'ECG', 'Protocol', '-1', '1', '1', '123', '123', '1', '12', '123', '0' );
SELECT LAST_INSERT_ID() AS lastID;

Column Names
Is there a way for me to title a colum "Some_Column_Name", but then be able to list it as "Some Column Name" in a web site? Perhaps with column comments?

Column Names
I've done searches on www.google.com and on this forum and I still haven't found any info on retrieving column names from a table.

Column Names In Mysql
how can i know column names starting with letter 'A' in a databse in mysql.

Identifying Column Names
PHP
environment
win XP
mySQL 5

I have myTable in myDatabase.

There are some columns in myTable, but I don't know their names and their attributes.

How can I identify them?

The would-be code below doesn't work correctly, but it will show what I want.
would-be code
show columns from myTable
target result
column1, column2, column3

Regexps Using Column Names
I want to match a "word" based on the column values of a table but only if the column value matches at the start of the "word".

Example:

table:
num | food
------|-------
78 | sausage
46 | banana
37 | egg

SELECT food FROM `table` where 78046 regexp num;

This select retrieves both "sausage" and "banana" (both 78 and 46 match in 78046).

What I want to retrieve is any food who's number matches at the beginning of the number in the select statement. E.G for above example, 78 matches at beginning of 78046, => "sausage". Normally using a regexp I can use the "^" to match at the beginning. But putting a table column (num) into the quotes, treats it as a string [ ...regexp "^num" ], and writing the carrot ^ bare is an error [ ...regexp ^num ]

Any ideas?

Get Length Of Column Names
is there a possibility to check if somewhere in a table/db a column exists whichs name is longer than, for example, 50 chars?

Exporting Column Names
I'm exporting MySQL data using a sql script containing::

SELECT * FROM (database name)
INTO OUTFILE (filename)
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '
';

The file is created successfully but line 1 of the file does not
contain the column names. Is there an option I need to enable in oder
to produce this?

Complex Column Names
i have a table with name table1. That table has a column with name thing1/thing2, when i want to do a query like:

select thing1/thing2 from table1;

shows an error sin it interprets as if i wanted the column thing1 divided by the column thing2 (their values).

How To Find Column Names?
I'm working on a site in php and I need about 20 different delete statements.
Now I was wondering if it was possible to make a function that would just need some parameters.

There's on problem I can't solve.;
in the general syntax "Delete from table where column_name = value"
I can't seem to find a way to implement the column_name except doing it manually..
I always compare the value with the column where the primary key is located

Is there a way to just say delete from table where primary key = value ?
or delete from table where column1 = value ?

if not is there a way to get the column names in a select command?
Like "Select column_names from table" ??

Show Column Names In Php
I am using php and mysql and I want to show the column names. How do I go
about doing this without hardcoding the headers in my php?

Getting Table Names As A Column
Let's say I have a database(mysql) with tables 1 to x (table1, table2,...)
Table1:
Columns: Description + Date

Now I want to get all the rows from table 1 and do a union with all the tablenames.

So my sql will be something like:
Select Description From Table1 UNION SHOW TABLES as Description ORDER BY Description Desc.

Column And Table Names
i have a large problem , my hosting wont give me access to my phpmyadmin and so I cant backup my database, So I looked to back it up using php which was complicated and confusing, so I decided before they cut me off completely I would write a sql statement to list all table names and then all table columns in each table. I dont mind writing each script seperately. i.e. list all table names, then write a script to view names of the column for each table. I only have 20 tables so no big deal, getting really desperate. If someone could either post a script they have I can copy and customise, or point me in a direction I would appreciate that. Im no idiot at sql, just have never had to do this before and am unsure how to go about it.

Extra Column Names
I am inserting data into an empty table that has some extra column names as compared to the original table. The sql is:
PHP Code:

INSERT INTO `new_table` (`course_name` , `course_number` , `section`) SELECT distinct `course_name` , `course_number` , `section` FROM `original_data` 


If the new_table contains exactly the same column names then the sql works. If there is one extra column then the sql inserts exactly one row. I changed the (`course_name` , `course_number` , `section`) to (*) but this produces an error.


Finding Duplicate Names In A Column
I have 2 field in my table as

id and name

id Name

1 asd
2 asd
3 asd
4 acv
5 USD
6 USD
7 acx
8 zxc
9 xcv
10 ZXb

I want to find out the duplicates names and their id and how many times a particular name duplicates ?

How To Differentiate Column Names In A Join?
I have table 1

It's column names are:

username - password - email

then there is table 2

It's column names are:

username - color1- color2

When I do the join statement it displays

username - password - email - username- color1 - color 2

If I want to call the username from the second table what would I have to do?

I know normally you use ' . $row['username']. ' in the echo statement to call the username, but what would I do in this instance?

Reserved Words As Column Names
My understanding is that using reserved words as column names is
allowable as long as they are quoted. I am trying to create a table
dynamically with columns defined by the first row of a text file I
import. Unfortunately, I have no control over the column names and
the data provider has chosen to use the word "USE" as a column name.
"USE" is a reserved word.

To handle this, I tried quoting the word during the CREATE TABLE
statement, as follows:

CREATE TABLE my_table (
'use' varchar(100)
)

But this is still causing an error. Any suggestions for avoiding the
obvious workaround of checking column names against reserved words and
changing them when there is a conflict? I'd like to use the column
names as defined by the data provider, if possible.

Running Query For Column Names
Is there a way to run a query just to see what the columns are in a database?

Column Names On Top Of The Query Output
Is it possible to get the columnnames on the first row of a query output? Is there a "flag" I have to add?

Using Database Contents As Column Names
I have two tables I'm trying to join up, and would like to know if the following is possible:

table1 :
SELECT * from mediatype

+-------------+---------+
| mediatypeid | type |
+-------------+---------+
| 1 | MP3 |
| 2 | ra_low |
| 3 | ra_med |
| 4 | ra_high |
+-------------+---------+

Table 2:
SELECT trackid, mediatypeid, url from media

+---------+-------------+----------------+
| trackid | mediatypeid | url |
+---------+-------------+----------------+
| 1 | 1 | mymp3.mp3 |
| 1 | 2 | myothermp3.mp3 |
| 1 | 3 | busted.mp3 |
| 1 | 4 | newmp3.mp3 |
+---------+-------------+----------------+

What I'd like to be able to get out of these two tables is a result
like this :

+---------|-----------|----------------|------------|------------+
| trackid | MP3 | ra_low | ra_med | ra_high |
+---------|-----------|----------------|------------|------------+
| 1 | mymp3.mp3 | myothermp3.mp3 | busted.mp3 | newmp3.mp3 |
+---------|-----------|----------------|------------|------------+

Is there a way to do this completly in SQL? or i could employ PHP to help out.

Is There A Dynamic Column-names Capability?
I would like to know how to turn off column names from within a sql script. I know that this can be done when starting mysql, but I want to know if there is a way to do this once the server is already running.

There does not appear to be a variable for column-names (using show global, session, or local I did not see anything that looked like it could be used), which sort of tells me that it is not possible to change the default enabled setting once the server is active. Does anyone know 1) if this is possible and 2) how it can be done?

Pattern Matching For Column Names?
I realize it's possilbe to use the '*' character to select all columns in a table, and to use the '%' character to look for patterns in the content of fields to filter rows, but is it possible to use a wildcard character to select mulitple columns with a similar pattern?

For example:

select t.wtg1* from table t

to get all columns with names that begin with 'wtg1'.

Column Names With Special Characters
i'll have to create some columns with special characters in the column names.
example:

create table PacketFilterLog (
PFlogDate datetime,
PFlogTime datetime,
SourceAddress varchar(25),
DestinationAddress varchar(25),
Protocol varchar(8),
`Param#1` varchar(8),
`Param#2` varchar(8),
TcpFlags varchar(255),
FilterRule varchar(16),
Interface varchar(25),
IPHeader varchar(255),
Payload varchar(255)
);

the proplem resides in:
`Param#1` varchar(8),
`Param#2` varchar(8),

mysql 4.0.16-nt does not accept these column names (and they have to be this way!).

Retrieve List Of Column Names From A Table
Can anyone tell me the function that retrieves a list of column names from a table? Sorry to bother with a small request but I'm having difficulty finding this.

Using Results From One Table To Populate Column Names In Another
I have a table of gene names. I would like to use this table to populate the column names of a second table (all these columns will be of the same type ie INT(4) to represent expression level). The list of genes is large so I don't want to type in the columns by hand.

Changing Attribute/column Names Once Created.
I've just created my tables in mysql, only I've just realised that one of my table names is wrong and wish to update it.

How do I do this? It's easy to update the data in the tables, but I don't know how to change the column names themselves. Will I have to drop the table and start again? Thinking of it, it does solve my problem, but I would still like to know how to update it.

Unknown Column - Variable Names As Strings?
I'm having some trouble inserting records into my DB. The values being written to the database are either the titles of my variables or I get an "unknown column" error.

The following is a printout of what's actually getting saved to the database, followed by the values that are supposed to be sent to the database (from form data): Code:

Export/import Of Column Names With Space
I am using MySQL 4.0. Say that I have a table named "mytable" having a column "ID" and a
column "test columnname".

When dumping:

mysqldump --opt DATABASE -uUSER -hHOST -pPASS > myfile.txt

it gives someting like:

CREATE TABLE mytable(ID int(11) NOT NULL, test columnname text NOT
NULL);

Then I use the mysql command to import myfile.txt in another database:

mysql DATABASE -uUSER -hHOST -pPASS < myfile.txt

but it fails with:

"ERROR 1064 at line 1: 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 'test columnname text NOT NULL)' at line 1"

Obviously, the mysql command can't handle column names with spaces. Is
this a bug? I would say so - mysqldump should put the column names
between quotes or so (alternatively, mysql shouldn't allow spaces in
column names).

My problem is that I have to work with these columns as they are.
They're also referred to from a lot of queries in the API's. Any
possible workarounds?

Select Column Names With A Regex Pattern
I need to select an unknown number of columns from a dynamically created table.
I would like to select only columns based on a pattern such as "%\_1_SCO" or "%\_3_SLH". I could do a select COLUMN_NAMES on the information schema and loop thru creating a prepared statment I suppose but I was hoping for a more elegant solution. What I am thinking is something like this:

SELECT (some column name LIKE "%\_SLO"), (some other column LIKE "%\_2_FSR"), etc..FROM someTable;

Copying Column Names And Properties From An Existing Table To A New Table?
I've got a table with 42 columns, set to different types (string, datetime, date, integer). It has 8 million rows. I want to make a new table with the exact same columns, but with no data in it. Is there an easy way to do this without re-defining every column?

Column Names With &quot;#&quot;
I migrated a db from Access which has a column name containing a '#'. I would like to rename the column, but I've been unable to do so. It appears that the query browser thinks '#' is the start of a comment. Is there a way to do this?

Invalid Use
I am having a problem with group. Following is my query but it gives an error of "Invalid use of group".

SELECT refMember.MemberAcroName, refMember.MemberName, Count(DistrictLevelInformation.FormID) AS Spread
FROM (refMember LEFT JOIN MainInformation ON refMember.MemberID = MainInformation.MemberID) LEFT JOIN DistrictLevelInformation ON MainInformation.ID = DistrictLevelInformation.FormID
GROUP BY refMember.MemberAcroName, refMember.MemberName, MainInformation.qYear, MainInformation.Quarter
ORDER BY MainInformation.qYear DESC , MainInformation.Quarter DESC , Count(DistrictLevelInformation.FormID) DESC

Invalid Use
I have tested my query on MySQL 5 and it works, sadly the server it is to be run on only has 3.
I was just wondering what I need to update in the following query to get it working on 3 or if it is even possible to get it running on 3.


Code:


.....
and keyword IN ('keywords')
group by
people
having count(*) >= 1
ORDER BY people ASC

Is It A Valid SQL Query ?
I wrote a query that is returning zero rows (in phpmyadmin) while it should return some rows. Wondering if the sql is correct.

SQL
SELECT m.id,
m.link,
m.name,
h.body,
REPLACE(h.menu_id, '*', ',') AS menu_id
FROM menu AS m,
help_base AS h
WHERE find_in_set(m.id, menu_id) > 1
AND m.droit = 'super'
AND m.FUNCTION = 'adm'
AND m.ref_id LIKE &#392;%'
ORDER BY m.ref_id

Actually I have a help_base table where the field menu_id is holding data like *125*52*896*12*. I want to match that with the id of tha table menu (125, 52, etc. are ids of menu) ... the field ref_id of menu is having values like 2b


Valid Query
Is this a valid mysql query
PHP Code:

$query = "SELECT * FROM ".$prefix."search WHERE category = '$location' AND (type = 'mid' OR type = 'mp3') AND size < '34' ORDER BY name ASC"; 

Not A Valid MySQL
That's the error, and usually the problem is with the sql query string, in syntax or content.
But the problem now is that some lads at my website forum (I'm the php/mysql moderator!) are getting that error the first time they try to run a script that connects to their database. Their database is ok. They can even run sql queries from phpMyAdmin. But, they still get this error when a script is run. Has anyone come across an error like this before? I was wondering it was some sort of permissions error with the scripts, but they can connect to the mysql server and connect to the database, simply not run a query.

Valid Characters
I have searched the documentation and am unable to find this information out.
What are the valid characters for a username and password for MYSql? Is it any character, including extended, in the current character set?
The version we are using is the 4.1.21 .

Invalid Index
I try to used the MyPhpAdmin 2.8.2.4 with PHP 4.4.4, MySQL5.0.2.4 and Apcache2 and I got this error, 'invalid Index'

Invalid Use Of Group By
I have the following query:

SELECT CLAIMPOLICYNUMBER AS Plan, PROVIDERSPECIALTY AS Specialty, TINNUM AS Tin, SUBTINSEQNUM AS SibTin, CHARGETYPECATEGORY AS ChargeCategory, SUM(BILLEDCHARGE) AS Billed, SUM(PAID) AS Paid, " + _
COUNT(DOCUMENTNUM) AS ChgCount
FROM BAT
WHERE CASENUM='0000911'
AND CHARGETYPE <> 'DENTAL' AND CHARGETYPE <> 'VISION' AND CHARGETYPE <> 'ADMIN'
AND PMTDATE >= '2005-06-01' AND PMTDATE <= '2005-06-30'
GROUP BY CLAIMPOLICYNUMBER, PROVIDERSPECIALTY, TINNUM, SUBTINSEQNUM, CHARGETYPECATEGORY
ORDER BY SUM(BILLEDCHARGE)

It works great without the ORDER BY clause, but with it, I get the aforementioned error.

Directory Name Invalid
For testing purposes I have PHP installed and I have MySQL installed on my local laptop. Windows XP Pro

I am just learning both of them. I have read quite a few chapters in the MySQL Manual. Enough to allow me to get around in MySQL and directly create tables an view information in them, upload .txt files into the tables, etc etc.

I am receiving an error when I try to connect to MySQL via a PHP script.
I have no problem connecting to MySQL via Command Line.

The error I receive is "The directory name is invalid."

Here is my code... I am not sure where to put the directory name or where to put the directory path in order to make it valid. I am not sure what directory it is talking about.

<html>
<head><title>Connect to MySQL</title></head>
<body>
<?php
//connecting to the mysql server uses a mysql_connect command.
$link = mysql_connect("locoalhost",$_POST['username'],$_POST['password']) or die("Connect Error: ", . mysql_error());
echo 'Successfully Connected.
';
mysql_close($link);
?>
</body>
</html>

Where exactly would I put the path to the directory or where would I name the directory?

Invalid Syntax
I am having trouble changing my password back to OLD_PASSWORD by the following :

mysql> SET PASSWORD FOR
-> 'some_user'@'some_host' = OLD_PASSWORD('newpwd');

When I do it, it says
ERROR 1064: 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 'OLD_PASSWORD ('newpwd')' at line 2

Connection Must Be Valid And Open
I am getting an "Connection must be valid and open" error. After some
research I have found two possible reasons for this: malformed sql or bad connection string. Since the error is being thrown on a second .executescalar statement I will assume the connection string is working. I have two questions. First - if I can cut and paste the sql
statement into mySql's query browser and it returns the information, is the sql malformed? (e.g. select user_id from cms.accounts where
user_id='scott@scottrider.com') Next - are there other reasons for the error message.

Mysql_fetch_array(): Argument Is Not A Valid
Can anyone tell me if the below php/mysql statement is wrong? When I run it on my server it gives me the error mysql_fetch_array(): supplied argument is not a valid MySQL result resource.

I have googled this problem to find out that i can put the '@' sign in front of mysql_fetch_array. This blocks the error out but still does not print out the variable I want it to! When I googled it I found so many errors the same. But none help me out!
The sql code works fine in phpmyadmin.

And I have checked the case on the text over and over.
My eyes are hurting from looking at the screen! Had to change my monitor background from blue to black!

Any ideas? I really am stuck with this!

$query = ("SELECT *
FROM cringeitwebsitequote
ORDER BY `__id` DESC
LIMIT 1 ");
while ($row = mysql_fetch_array($query)) {
$hosting = ( $row[hosting]); {
$pages = ( $row[pages]); {
$forms = ( $row[forms]); {
$cart = ( $row[cart]); {
$products = ( $row[products]); {
$logo = ( $row[logo]); {
$flash = ( $row[flash]); {
$dhtml = ( $row[dhtml]); {
$statistics = ( $row[statistics]); {
}}}}}}}}}}

print("$hosting");

This should just print the work 'No'

Connection Must Be Valid And Open
am getting an "Connection must be valid and open" error. After some
research I have found two possible reasons for this: malformed sql or bad connection string. Since the error is being thrown on a second .executescalar statement I will assume the connection string is working. I have two questions. First - if I can cut and paste the sql.

statement into mySql's query browser and it returns the information, is the sql malformed? (e.g. select user_id from cms.accounts where
user_id='scott@scottrider.com') Next - are there other reasons for the error message.

Invalid Use Of Group Function
I have the following Sql Statement... I'd like to find the sum of hrs worked by an employee in the month, the required number of hrs, and the sum of the difference between the two, the worked hrs are calculated by subtracting the max vtranstime - min vtranstime and the required hrs are calculated by subtracting max to1 - max from1....

I tried to do the following:

select sum(timediff(max(vTransTime),min(vTransTime))) as worked,
sum(timediff(max(translog.to1),min(translog.from1))) as required,
sum(timediff(sum(timediff(max(vTransTime),min(vTransTime))),
sum(timediff(max(translog.to1),min(translog.from1))))) as overtime,
empid,deptname, firstname,lastname from employee,translog,department where
employee.emp_magnetic_num=translog.vId
group by employee.empid
I am getting the following error :
Invalid use of group function

Invalid Backup File
I am tring to restore a .pmb backup file and getting the message "Invalid backup file". I am very new to myssql so I don't have a clue what that means. Wrong version of mysql? Corrupted file?

Invalid Use Of Group Function
Using mysql 4.0

I get the following error message

"Invalid Use of group function"

with the following code:

update custRP c, tbl_acctbal a
set c.rpBal = sum(a.currRPBAL)
where c.custid = a.custid

Invalid Argument While Using BCP (Script)
This will be a 50/50 question. It's either something that the SQL experts can answer or a scripting forum. I'm new to SQL and just coming to grips with getting familiar with scripts. I've developed a small script for my workplace that will connect to a remote server and extract the specified table that I want, zip it up and then copy it back to my local machine. This works fine until it tries to run the bcp command.
If I tivoli to the remote machine and type the bcp command in command prompt it works fine. However when executed from the script it throws an invalid argument and seems to refer to the "-" minus I place in front of the U (user) or P(pwd). The script echos the users table request to a file which is then copied to the remote server (SQLtable.cmd) and then PSEXEC is called to connect to the server and run the script. e.g. psexec \%Server% -u %user% -p %password% "C: empSQLtable.cmd"
PSEXEC then returns the following error.

C:WINNTSYSTEM32>Bcp FrontOff..SHIFT_TER_DATA out C: empdmpnlSHIFT_TER_DATA.dat ûUsa ûPpwd (chopped off the -n)
Unknown argument '¹Usa' on command line.

Sorry about all the data, just hope someone can help. Must be an easy way. The small script which psexec is executing contains two simple lines. Bcp FrontOff..SHIFT_TER_DATA out C: empdmpnlSHIFT_TER_DATA.dat -Usa -Ppwd -n
wwzip -9 C: emp\%username%SQLtables.zip C: emp\%username%*.*


Copyright © 2005-08 www.BigResource.com, All rights reserved