Using Table A Column Row Data For Table B Column Headings
Is it possible to add column data in table A and have (dynamically
linked) table B column headers?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Column Headings At The Bottom
While watching a realtime data acquistion system's MySQL table fill, I routinely run "mysql> SELECT * FROM TABLE". After 300+ rows scroll by [in text mode under *nix], I've usually lost track of which column [out of 23] belongs to what datafield. Is there an option to have the "mysql" tool repeat the column headings provided at the beginning of select after the last row? At the moment, I use: mysql> select * from en; select * from en order by date desc,hour desc,minute desc limit 1; but the column widths do not match up [due to 0s where NNNN might have existed eariler].
Adding New Column In A Table With Data From Another
I have been trying to accomplish the following aince quite some time.. I have tried various combinations of Union, Merge, Insert.Select, etc.. Tables: table_1 with 22 data columns, and a autoincrement primary key column. table_2 with 1 column (newtimenumber in query below) with double values, no primary key. (Although i can generate it) Relation between tables: The number of rows in both the tables are same, and if required can be mapped on one to one basis. (Not yet done as i have not assigned primary keys to the table_2; but row 1 of table_1 corresponds to row 1 of table_2) The table_2 is generated by performing a set of calculations on one of the columns in table_1; hence they correspond to each other. Problem: I want to insert the all the rows in table_2 into a new Column (newtimenumber in query below) in table_1; but maintaining the corresponding row by row relation. Tried Insert..select : INSERT INTO dbname.table_1 (newtimenumber) SELECT swapper.newtimenumber FROM dbname.table_2 this did not work, and generated new column in table_1 but the rows were appended at the end. I would be very glad if some one could help me with this. I have tried many things, but i am not getting something right.
Delete Rows From Table A, Which Dont Exist In Table B (base On Column X)
I have 2 tables identically structured. A & B Table A, has column: Product (product code) as primary key Table B doesn't. Apart from that they have the exact same fields. There's also a column: supplier I want to Delete * from table A, where does not exist in B (based on column: Product) & where supplier = apples So to elaborate. Table A is my main table, but it now contains outdated products from supplier apple. Table B has the latest list of products from supplier apple. So I want to remove old products from A that supplier apple no longer makes. mysql version 4.0.27
1036:Table Read Only Error, Cant Add A New Column To My Table
I have a table with arround 30 columns, and I am trying to add another column to it with the following query. alter table tablename add column column_name varchar(10); and I get the following error. ERROR 1036: Table 'ProfilesDesc' is read only what could be wrong?
Update Column In Table A With The Count Of Another Table
Having my SQL-background in Oracle I'm looking for the MySQL equivalent for: update tableA set column1=(select count(*) from tableB where tableA.key= tableB.key) cannot find anything similar in the manual, but probably overlooking something.
Create Table / Column Table Order
When creating a table, is there any advantage in specifying the columns in any special order? For example, what about columns with data used more frequently listed first, or column/data types giving some? Or.... am I being pedantic even thinking about such?
Another Column Or Another Table?
I have a table which will typically have approximately 3000 rows. When displaying the data on a webpage I want to display some of the rows in a different format based upon the data. For example, I may have 3000 items and I might want to change the display format for only 12 of those items. My options are to have an additional column in the main table which will just be a tinyint(1), so basically a boolean to say that item needs treating differently. Or I can have another table to store the items id and so flagging it for different display. I also need to do the same for highlighting certain items so again I'd either need a another column with a boolean or a third table to store the item id. Its going to be far easier from a coding and management point of view to have 2 extra columns with a boolean value. But is it better to have 2 extra tables?
Table Column
what type of a query can i use to change column value into utf8 table which column value is latin1_swedish_ci ( i do not know which table have column value is "latin1_swedish_ci" ) and this query must run on just db i will select
Column In Table
I have a column... name product_image it has a bunch of images that are uppercased. I am trying to make everything in that column lowercased, and also trying to make it so every future record that is entered is lowercased. What is an SQL Query that I can put in to change the settings so that this can happen, to just make everything already entered and that will later be added lowercase.
Order By Value In Another Table Column
myTable1 (n) city (1) Tokyo (2) New York (4) Chicago (5) Peking (6) Nagoya (7) Paris myTable2 (n) cate (2) 1 (6) 5 (6) 9 (7) 4 I have data above in myTables. I like to produce myTable1 records ordering by myTable2 cate column. The following is one of my trials. trial code select myTable1.n,city from myTable1 join myTable2 on myTable2.n=myTable1.n where myTable2.n is NULL or myTable2.n=myTable1.n or myTable2.n<>myTable1.n order by myTable2.cate, myTable1.n trial result (2) New York (7) Paris (6) Nagoya (6) Nagoya The following is my target result. target result (2) New York (7) Paris (6) Nagoya (1) Tokyo (4) Chicago (5) Peking
Table Name Stored In Column
CREATE TABLE `tags` ( `id` int(11) NOT NULL auto_increment, `tag` varchar(255) default NULL, `quicklink` varchar(255) default NULL, `related_table` varchar(255) default NULL, `related_id` int(11) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; In this tags table i save the information which other record from another table relates to. For example for a record in the tags table i could have 'people' in the related_table field and 񟝧' in the related_id field. This would imply that this tag relates to record 1015 in the peoples table. Clear enough i guess? Now i want to generate a tagCloud, therefor i have the following query which works perfectly. SELECT t.tag, t.quicklink, COUNT(t.tag) AS cnt FROM tags AS t GROUP BY t.tag The problem now is that we need to add one extra field to all the related tables called 'status' which is either 1 or 0 and indicates wether the record is active or not. The results from the tagcloud query above should only contain the tags that are related to a record that has status = 1 and that is where my problem comes up. How can i limit the tagcloud query to only count tags of which the related item in the related table has status 1?
Finding The Last Column In Table
Is there any way I can find the last element of a table in a certain column besides using a while loop to go through till I reach the last element. If its the while loop, i presume its this:
Adding A Column To A Table
I am looking to add a column to a table, however I only want to add it if it doesn't already exsists. Is there a command to do this?
Table Column Issues
i av a table with a column containing categories some addresses belong to, occuring a number of times. i'd however luv to get each distinct category in the column with their number of occurence. As in something like this: ---------------+----- CategoryNameA | 5 ---------------+----- CategoryNameB | 10 ... and so on. How do i go about it?
Copying A Column Within A Table II
I'm trying to copy a column (Open) from a table into another column (Close) from the same table but skipping the first "cell" from the source column (Open). I tried the following query: UPDATE Table SET `Open`=`Close` WHERE `ID`="2"; The query copies the whole source column (Open) into the destination column (Close) including the "cell" I'm trying to skip.
Column Derived From Another In Same Table
Is there a way to have one column have its data derived from another one? I have a table with a `datetime` and I want just DATE(`datetime`) for each of them. At the moment, I'm just running DATE(`datetime`) on the output of my query, but that seems a little wasteful when there the output is large. Furthermore, nearly all (but not all) my queries use the DATE(`datetime`) rather than the full `datetime`. I guess I'm looking for something like in a spreadsheet, where the element is defined as a forumla of another element(s), and so I can update one and the other would automatically update. Such results could be preprocessed and cached by the server, and everything would run much more quickly. I guess I can make a view (if my server wasn't on v4), but that would then require a join and, since that's done pre-query, it's expensive since the view's select is done for every row of the table.
Comments Per Each Table Column
I see in phpmyadmin and MySql's very own Browsing tool there is a comment column associated with each column within a table. Obviously this is ideal for labeling your primary key, or even identifying strange (short formed) column names. But how exactly do you get it so that you can input data in this comment area? I understand how to add comments to the tables (themselves) but not to the individual columns.
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.
Copy Column From One Table To Another
I have managed to get: update table_A , table_B set table_B.col_1 = table_A.col_1 where table_B.col_# = table_A.col_# to work on PHPMyAdmin 2.6.1-pl3 with MYSQL 4.0.16 but it will not work on PHPMyAdmin 2.6.0-pl3 with MYSQL 3.23.58;
Asking Table.column[0] Name In Mysql
I have want do make a dynamic query, without knowing the first column and thus avoiding to name all colums id. eg. select * from A, B where A.column_name[0] = B.column_name[0] I'm thus interested in column_name[0]
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.
Table With Single Column
I'm dealing with an online store in which the "catalog" table is already filled with data and I don't want to mess with it. But I need to allow items to be marked as "tax exempt". I'm thinking the easiest way to do this is to just create another table called "taxExempt" with a single column called "sku", which is the unique ID for any given item.For some reason it strikes me as silly to create a table with just one column. Is this generally an ok thing to do, or is there a better way to approach this?
Indexing A 2 Column Table
I have a 2 column table that looks like this: id (Smallint) | userid (Mediumint) I have to use id and userid in my where clause together, so I was thinking of creating 1 PRIMARY KEY on both of these columns, but is this necessary? My table won't have more than 2 columns, would an index be necessary?
Create Table Column
I'm using MySQL 4.1.7 on FreeBSD 5.3. I'm trying to add a column named foreign and it keeps kicking back an error. I realize foreign is a function call of sorts...but is there a workaround? I've tried adding it using the add table syntax and alter table...both are unsuccessful.
Fetching Highest Column Value, From A Table...
To simplify things, lets say l've got a table, with three columns... an auto-increment ID, the user's name, and their age (which is an integer). lets say my column has five rows: TABLE NAME: my_users column 1 | column 2 | column 3 [ID] [NAME] [AGE] ------------------------------ 0 | Bill | 23 1 | Bob | 18 2 | Eric | 37 3 | Steve | 58 4 | Frank | 19 ------------------------------- Now, lets say l wanted to tell the user who the oldest user in table was, with something like: Hello, our oldest user is $oldest_age and our youngest user is $youngest_age $sql = 'SELECT age FROM `my_users` WHERE ... ???? obviously Steve is the oldest as he's 58, and Bob is the youngest at 18... However l was wondering what the most efficient way to select this data quickly from the database would be? Though this example is small, l've got 10,000 rows in the actual application l working with here, so a while loop won't really cut it
How Do You Link A Table To Two Tables Using One Column???
l have created 3 tables in mysql, table A, table B and table C. Table B and C have a column - primary key with the same name and data type and length. l have created 2 foreign keys for Table B and C in table A (on the same column (column name = ID) in table A which links to the ID columns in Table B and Table C. The ID columns in Table B and Table C use auto increment and start at different numbers - for distinction purposes. Table B starts from 2 and table B starts from 5000. Both tables A and B have data in them. This works so far. however, when l try to insert data into table A, its only checking if the foreign key exist in table B. How do l make it check table C as well?
Calender Table - Time Column?
I am currently in the process of building a calender/date MySQL table that will be searched for available dates for holiday tours? I want to use a time column as there will be a restriction on places for up to 3 days so this will have to be taken into account.
Change The Sequence Of Column In Table
I am using MySql Query Browser I want to change the Sequence of Column in data table e.g. Before : table sequence is (UserID, Name, BOD) After : table sequence is (User ID, BOD, Name) How can I do that?
Adding And Populating A New Column In A Table
I would like to add a new column to an existing table, with the following caveats: 1. For existing records, a fixed value (same value for every record) should be added in the new column. 2. This value should not become the default value for records created in the future. For reference, the column I want to add is Year. Existing records should have this set to 2006, however future records will be set to their respective year. I know I can do this in two steps - ALTER table to add the column and then UPDATE to add the value 2006 to each record, but I was wondering whether there was a way to do it all in one go.
Search Table Column For Existing Value
I would like to search a table's column so that I can match an entered email address against the data in that column. I'm writing an aplication for an event and I don't want duplicate email addresses in the table. I'm using PHP4.
Update Using Like Wildcard And Table Column
I'm trying to update table 1 with data from table 2 where the data in table 1 is like the data in table 2. I need to use the % wildcard but I can't seem to get it to work using a column name. Is this possible, or am I going about this the wrong way. Here is the statement I have, it only updates records that match exactly. update crowley_preowned,models set crowley_preowned.po_display_model = models.model where crowley_preowned.po_model like models.model po_models contains say PT CRUISER LXI, models.model contains PT CRUISER. I want to update po_display_models with PT Cruiser from model for any record that starts with PT Cruiser.
How To Keep A Table Ordered By A 'date' Column
how should I keep my "deliveries" table sorted by "date" field ? I found a solution with " ALTER TABLE 'deliveries' ORDER BY 'date' " after every INSERT I make , but I'm not sure it's the fastest way. I couldn't find the algorithm used for sorting so I'm not sure it's optimised for sorting where only one record is out of it's place.
Combine Records Of A Column Of The Same Table
i have all my portal contents on the SQL Database in the following manner: Node_id Contents 12 this the first page 12 welcome to the portal 12 this is some sample data 13 this the second page, 13 sample data when a page is being loaded, depending on the node_id contents are retrieved and displayed. Now i need a query which would combine all records of the same Node_id (page) and display as one record. Eg: Node_id Contents 12 this the first page welcome to the portal this is... 13 this is the second page, sample data
If Record Exist In 2 Tables, Use Column Of Table B
I have 2 tables A and B... Table A: A_id, field1, field2, ..., status Table B: B_id, A_id,..., status I need to select all info from table A. And if a record exist in table B, i need to use the status value of that table instead of the one in table A. Im not sure how to do it...with EXISTS or CASE?
Distinct Column In Multi-Table Query
I want one article from each 'sub topic'. Each sub topic is given a 'sub_id'. PHP $garticle = mysql_query("SELECT DISTINCT(feeds.sub_id), articles.title, articles.feed_id, articles.abstract, articles.link, articles.date, site.articles, $formula AS importance FROM articles,feeds,site WHERE articles.date > DATE_SUB( now() , INTERVAL 1 day ) AND articles.feed_id=feeds.feed_id AND feeds.site_id = site.site_id ORDER BY articles.article_id DESC LIMIT 16", $connection) or die(mysql_error()); The article has a 'feedIid', this JOINS the feeds table. The feeds have a 'sub_id'. I only want the 16 most recent articles from DISTINCT 'sub_id's
LIKE Search On Joined Table Column Syntax
I'm struggling with doing a wildcarded search between columns on a joined query. If I do the following: select * from t1, t2 where t1.str1 like t2.str2 I get what I expect. However, if I do the following: select * from t1, t2 where t1.str1 like '%t2.str2%' I get no matches. Is the t2.str2 getting taken literally, and so there are no matches? If so, what is the proper syntaxt for this?
How Do I Test If A Value Exists In A Table Column With A Query?
I know this is probably something that should be obvious or easy, but I can't figure out how to test whether a value exists or not. For example, in table "bookgroup" in the "meetingdate" column (which contains dates for meetings), how could I test whether the date "20040307" exists? I don't want to return a value in the same row... I simply want to return a boolean TRUE or FALSE value... like 1 if it does exist, and 0 if it doesn't. Can I do this without creating another column specifically for this purpose? Is there a query which can do this? All I have so far is FROM `bookgroup` WHERE meetingdate='20040307' but I don't know where to go from there.
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.
Reference A Table Name In A Join (use A Table's Name In A Column)
I want to make a column while joining several tables that stores the name of the table each record came from. e.g. lets say I have three tables dogs, cats, and mice. when I do a join, I would like to create a column on the fly labeled say, species, that simply references the table name from which the record is coming from.
SELECT DISTINCT On A Varchar Column (big Table)
I have a table with 10 million rows in it. Now, I need to export a list of unique values from a varchar column. Normally I would do: SELECT DISTINCT MyColumn INTO OUTFILE '/dumpfile.txt' FROM MyTable But this is VERY time consuming and slows my PC down. Can you give me an advice about what should I attempt to make it last the less? For instance, should I create an index on MyColumn AND THEN execute the SELECT DISTINCT? I may look silly, but I also tried using a Memory table thinking I would cut the indexing computation time but my RAM is not big enough to contain all the rows.
|