How to query database column names? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a table with multiple columns starting with one keyword link_. I.E. link_0_10, link_10_20, link_20_30 and so on.
I want to select only columns starting with these link_ keywords. How to do that? I can query by RegEx on the value, but on the columns? I have not been able to.
P.S.: I have no prior idea of how many columns may be present.

just change database name and table name with yours and run this query
SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='database_name'
AND `TABLE_NAME`='table_name' and COLUMN_NAME like 'link_%'

SELECT *
FROM information_schema.columns
WHERE table_name = 'mytable' and column_name like 'link_%'

Related

Display/create a blank row in between data set and breack the table data using php/mysql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am using one table and two queries to display the below output.
Here I have used 1st query to display the morning/middle/evening and other to get the user details.
I want to user a empty/blanks row after the last morning/middle which need to have this output
Expected output:
Can anyone help me on this.
Not knowing your SQL statemanets, i would only advise to use
UNION ALL
(See Docu here)
So your Statement would look somehow like that:
Select Col1, Col2
from tbl1
UNION ALL
Select NULL as Col1, NULL as Col2
UNION ALL
Select Col1, Col2
from tbl2

Select and sort data from one table on certain columns [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm looking to see if it is possible to select data from table A with a sort so the order of the data changes.
I then want to make a loop so it will go through each row and add it into table B.
Is this possible.
Use a variable #row_number to store the incremented num for your expected sorting.
SET #row_number = 0;
SELECT (#row_number:=#row_number + 1) AS num, Column1
FROM TableA
ORDER BY Column1
This result can be store in temporary table and based on that you can do loop/insert into the TableB

How to search a CSV column for a value in MySQL? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to select those ids where staff id contain 3. Below is my database structure:
ID NAME Staff_ids
-----------------------
1 A 0,212,5
2 B 2,3,600
3 C 0,1,4
I want a query where I can select those ids having 3 in staff_ids column. How can I do that please help
You can use FIND_IN_SET.
Here is SQLFiddle Demo
Input :
Output:
SELECT * FROM table_name WHERE FIND_IN_SET('3',Staff_ids)>0
Hope this helps.
SELECT *
FROM ABC
WHERE Staff_id IN ('3');
Check if this helps

query="SELECT * FROM Table WHERE `VarCharCol1`= numeric" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a table with varchar column, this column contains both numeric records and AlphaNumeric records, but require only the ones that have no letters.
How can I achieve this?
Try this:
SELECT * FROM table WHERE `varcharcol1` RLIKE '^[0-9]+$'
tryed
SELECT column_name FROM table WHERE ISNUMERIC(column_name) = 1
select * from table where concat('', column * 1) = column;
Returns array of data, where column is numeric (contains only digits).

Select entire table contents and insert into another table with the same column names [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have two tables that have the same column names. Is there a way of getting the contents from one table and inserting it into another. I could export it into a sreadsheet then import it into the other table but would prefer to quickly use mysql. My experience with php and mysql is mainly selecting and inserting from one table.
Use INSERT ... SELECT:
INSERT INTO table1 SELECT * FROM table2
Note that this will only work if the tables are defined with columns in the same order; otherwise one will have to explicitly name the columns in one (or both) of the INSERT and SELECT parts of the command:
INSERT INTO table1 (colA, colB, colC) SELECT colA, colB, colC FROM table2

Categories