LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-25-2010, 10:57 PM   #1
MartyJay
Member
 
Registered: Oct 2005
Location: Newmarket, On
Distribution: Debian Squeeze
Posts: 55

Rep: Reputation: 15
Completely emptying column in mysql


I have a database with the following table (see below).
What I need to do is to emty the itype column completely, so that if I do a SELECT itype FROM items; it will return empty set.
I have tried dropping and recreating the itype column, but it just adds the data I want to insert to the end, and even when I recreate it, it is not empty.. I need to overwrite it, or better, start with an empty column.
How can I do that?

mysql> desc items;
+----------------------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+-------------------+----------------+
| itemnumber | int(11) | NO | PRI | NULL | auto_increment |
| biblionumber | int(11) | NO | MUL | 0 | |
| biblioitemnumber | int(11) | NO | MUL | 0 | |
| barcode | varchar(20) | YES | UNI | NULL | |
| dateaccessioned | date | YES | | NULL | |
| booksellerid | mediumtext | YES | | NULL | |
| homebranch | varchar(10) | YES | MUL | NULL | |
| price | decimal(8,2) | YES | | NULL | |
| replacementprice | decimal(8,2) | YES | | NULL | |
| replacementpricedate | date | YES | | NULL | |
| datelastborrowed | date | YES | | NULL | |
| datelastseen | date | YES | | NULL | |
| stack | tinyint(1) | YES | | NULL | |
| notforloan | tinyint(1) | NO | | 0 | |
| damaged | tinyint(1) | NO | | 0 | |
| itemlost | tinyint(1) | NO | | 0 | |
| wthdrawn | tinyint(1) | NO | | 0 | |
| itemcallnumber | varchar(30) | YES | | NULL | |
| issues | smallint(6) | YES | | NULL | |
| renewals | smallint(6) | YES | | NULL | |
| reserves | smallint(6) | YES | | NULL | |
| restricted | tinyint(1) | YES | | NULL | |
| itemnotes | mediumtext | YES | | NULL | |
| holdingbranch | varchar(10) | YES | MUL | NULL | |
| paidfor | mediumtext | YES | | NULL | |
| timestamp | timestamp | NO | | CURRENT_TIMESTAMP | |
| location | varchar(80) | YES | | NULL | |
| onloan | date | YES | | NULL | |
| cn_source | varchar(10) | YES | | NULL | |
| cn_sort | varchar(30) | YES | | NULL | |
| ccode | varchar(10) | YES | | NULL | |
| materials | varchar(10) | YES | | NULL | |
| uri | varchar(255) | YES | | NULL | |
| itype | varchar(10) | YES | | NULL | |
| more_subfields_xml | longtext | YES | | NULL | |
| enumchron | varchar(80) | YES | | NULL | |
| copynumber | varchar(32) | YES | | NULL | |
+----------------------+--------------+------+-----+-------------------+----------------+
37 rows in set (0.05 sec)
 
Old 03-26-2010, 01:00 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
My sql's pretty rough but maybe something like:

Code:
update items set itype=''
.. hope this will point you in the right direction


cheers

Last edited by kbp; 03-26-2010 at 01:02 AM. Reason: noticed the table name...
 
0 members found this post helpful.
Old 03-26-2010, 08:12 AM   #3
MartyJay
Member
 
Registered: Oct 2005
Location: Newmarket, On
Distribution: Debian Squeeze
Posts: 55

Original Poster
Rep: Reputation: 15
Nope, that's not it.

Thanks, I tried that already, but then I still have something in my column. I need it to be completely empty.

Quote:
Originally Posted by kbp View Post
My sql's pretty rough but maybe something like:

Code:
update items set itype=''
.. hope this will point you in the right direction


cheers
 
Old 03-26-2010, 01:29 PM   #4
MartyJay
Member
 
Registered: Oct 2005
Location: Newmarket, On
Distribution: Debian Squeeze
Posts: 55

Original Poster
Rep: Reputation: 15
mysql, copying data from one field to another

Maybe it's better to describe what I need to do.
I have a table called biblioitems that contains a column called itemtype.
I need the data from that column in the column itype of the table items.
I have tried a few different ways, but the problem is that mysql just adds it to the column. (It is rather long by now...) I tried dropping and recreating the column, but it still has many fields in it after recreating?? All I need is the data in the itype column.
 
Old 03-26-2010, 05:39 PM   #5
MartyJay
Member
 
Registered: Oct 2005
Location: Newmarket, On
Distribution: Debian Squeeze
Posts: 55

Original Poster
Rep: Reputation: 15
Solved another way;

Ok, I have solved it. With a temporary table and an UPDATE statement, thanks to Yang Yang.
Here's the link;
http://www.kavoir.com/2009/05/mysql-...1#comment-9461
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
maybe simple mysql q: how to tell which column to 'DISTINCT' BrianK Programming 6 12-06-2007 06:52 PM
MYSQL search query by column name using wildcard AQG Programming 9 08-07-2007 09:41 AM
updating a column in MySQL mohtasham1983 Programming 1 10-28-2005 10:01 AM
How to delete a column in MySQL ? indian Linux - General 2 10-15-2004 01:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration