I have a table with 21 columns and I need to find all column names that have a specific value in them. This goes beyond my knowledge of database querying.
If this is possible, how would I do this?
Do you need to find columns in which the name of the column contains a certain value or there exists a row in which the given column contains the given value?
In the first case you could try the show columns: http://dev.mysql.com/doc/refman/5.0/en/show-columns.html
Related
I have created a new column in the "destination" table with the same name, datatype and other values as appear in the "source" column in a different table. I have tried many suggested solutions as found on stackoverflow. This one appeared to work (found on Quora) but when I went to the destination table the previously empty column remains empty with nothing but NULL values noted. This is the Quora suggestion:
you can fill data in column from another existing one by using INSERT INTO statement and SELECT statement together like that
INSERT INTO `table1`(column_name)
SELECT column_name FROM `table2`
here you filled a single column in table 1 with data located in a single column in table 2
so if you want to fill the whole table 1 (all columns) with data located in table 2 you can make table 1 like a copy of table 2 by using the same code but without column name
INSERT INTO `table1`
SELECT * FROM `table2`
but note to do this (copy table content to another one) ensure that both of tables have the same column count and data types.
I'm not sure what is meant by column count (do the two table have to have the same number of columns?)
When I run it I get error # 1138.
Any help greatly appreciated. -JG
I have a column with field ids
ids contains value like
1,2,3,4,....
Now I want to check an Id=4 in ids field
You can use find_in_set
select * from your_table
where find_in_set(4, ids) > 0
But actually you should rather change your table design. Never store multiple values in a single column.
You can also used array for Checking it. but the stracture of the table should have to changed it would be good.
How can I get a List of table names and column names in a database where a column value like '%something%'
For an example, I have a Movie database, I need a List of table names and column names where the column value = 'tom cruise'
I am using MS SQL and MySQL database
Thanks
Check out this previous question and answer... the answer contains a script that scans a database and lists out all the tables/columns with a matching value:
Selecting column names that have specified value
You can get tables names and columns names using information_schema.
And Information_schema contains following column names using which you can filter your results:
I have a MySQL table called settings. It has multiple columns, where every column is an item with a single value. So it has only one row and no id column. The design is final (I don't plan to add more columns).
How can I update the value in a single column (change one setting's value)?
What's the problem with using this --> http://dev.mysql.com/doc/refman/5.0/en/update.html
?
UPDATE table1 SET column1 = value
In case you have more than one row, you can add:
WHERE table1.column = matching_value;
making sure the match criteria is only the row you need.
to update a value of certain item column you must specify the row contains the value to be updated, since you don't have a primary key, you can depend on the nature of item values to act as row identifier and i don't recommend that.. the best way is to update your design and add column for the primary key
I need to get list columns of some temporary table (MyISAM) in MySQL in view like number column - name column.
I need to know number of column with specific name. In advance, I can't know what is the number of column - I'm using dynamic sql with some variables to create temporary table.
I can not use show columns... because I can't work with results of this function. I can't use INFORMATION_SCHEMA.COLUMNS because it does not contains columns of temporary table.
Some ideas?
Thanks in advance!