place an existing column at first position in mysql [duplicate] - mysql

This question already has answers here:
How to rearrange MySQL columns?
(6 answers)
Closed 9 years ago.
please tell me how to place an existing column(contained values) at first position in mysql. Suppose i have a table EMP_DTLS and there are columns like NAME, SALARY, DOJ, DOB, EMAIL_ID, AND EMP_ID contains values in every columns. Now i want to place this EMP_ID at first position.
Thanks in advance.
I have tried the queries those are discussed here previously but those aren't working for me.

ALTER TABLE EMP_DTLS MODIFY COLUMN EMP_ID INT(10) FIRST
Just use the correct type,i used INT(10)

Related

How can i combine the values from 3 varchar columns to one column? [duplicate]

This question already has answers here:
MYSQL - add new column with default string concat with data from existing column
(2 answers)
String concatenation in MySQL
(5 answers)
Closed 11 months ago.
For Example
I have the following Columns in a DB-table: Name, Surname, Adress, Contact.
In one row the value for the column name is Smith , the surname Bob and the adress Street1.
How can i combine the mentioned values to the column Contact?
The Value in this row should be like this then:
Bob_Smith_Street1
I want this to be automatically created in the table. so as soon as I right click on the Table -->select 1000 rows, the value is displayed. Without having me to enter the mentioned select command. Is this possible? Can anything be done when creating the table for this. So for example create table employees (Contact(name""surname""address)).
thanks
ps. sorry for my bad english:)
Use CONCAT(). For example:
select concat(Name, '_', Surname, '_', Adress) as contact from t

remove if not matched in another table [duplicate]

This question already has answers here:
Delete sql rows where IDs do not have a match from another table
(4 answers)
Closed 1 year ago.
I have a MySQL database where i want to clean up a table but i do not know how to compare against other table entrys and hope someone can help.
One table in the database is called "stats". in the table "Stats" there is a row called "Page_title" which holds an ID number. The same ID number should exist in the table "url,id" otherwise that entry from "stats" should be removed, how can this be done?
Please see this image for reference.
You can do this with a sub select:
delete from stats where page_title not in (select id from shorturl)

How to change All column name as lower case in Mysql table? [duplicate]

This question already has answers here:
Mysql - Rename all tables and columns to lower case?
(6 answers)
How to automatically convert a MySQL column to lowercase
(3 answers)
Closed 4 years ago.
A MySQL table contains almost 17 fields. for example
P_ID
P_NAME
P_ADDRESS
P_SERVICENO
etc..
how to change these all field name as lower case in a single query in MySQL.
Check this:
ALTER TABLE `table_name`
CHANGE P_ID p_id varchar(10),
CHANGE P_NAME p_name varchar(10),
...

Retrieve data from two table using id [duplicate]

This question already has answers here:
SQL query return data from multiple tables
(6 answers)
Closed 5 years ago.
Table1
Id, name, addresses
101,raja ,chennai
Table2
Id,group,name
101,a,siva
102,b,selva
I want retrieve data from two tables like
Table2.group=a and two table Id must equal then take address from table1 display
Id, name, Address, group
What have you tried so far? Have you taken a look at some of the resources here?
Since this is the type of pretty straightforward SQL query you're likely to do many times over, it's worth you reading the tutorials and learning it yourself. I'll give you a few pointers to begin:
Your two tables are connected by the Id field (most likely, this is the primary key for one table and the foreign key for another). You'll need to JOIN these two tables using that field.
You'll need to specify a WHERE clause to filter for your condition that Table2.group = a.
The fields you want to display can all be specified using SELECT. If you are selecting data FROM Table 1 and joining to Table 2, you won't need to specify the table name before the field name.

How do inserts into mysql views? [duplicate]

This question already has an answer here:
Is it possible to insert data into a MySQL view?
(1 answer)
Closed 2 years ago.
i have 2 tables
table.employees
id, first_name, last_name, post
table.time
employee_id, work_time
VIEW
id, first_name, last_name, work_time
how i can write one insert for VIEW !!?
You can't. It's not (always) possible to determine which values would need to be inserted. For example, your view doesn´t have the post column, which might be required, which would make it impossible to insert through a view.
As such, VIEWS are for viewing content only; insertions have to be made on the actual database tables.