How do inserts into mysql views? [duplicate] - mysql

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.

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

insert in two table with join such that id of one table is to insert in another table [duplicate]

This question already has answers here:
MySQL, passing a AUTO_INCREMENT to another table
(2 answers)
Insert ID from one table to another in MySQL php
(1 answer)
Closed 5 years ago.
I have two tables booking and client. Booking table will have client's id. Now I want to ask for booking detail first and then user detail next. The problem for me is when I insert booking detail first then insert user detail next I have to insert user's id in booking table. how is it possible?
note:i have to do in core php.

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.

Generate next Registration Id from database [duplicate]

This question already has answers here:
Generate next Id as per the max id in database using Java
(2 answers)
Closed 8 years ago.
I am working on a web application. It will have multiple users. I am using mysql as database.
In my application i am fetching the latest id (from the database, using max(id)) , and then generating the next id for the new registration. This approach is incorrect, as the id might change between the time i update an id
How should i proceed?
LAST_INSERT_ID() or AUTO_INCREMENT will be your friends
LAST_INSERT_ID() :
INSERT INTO table (id, field) VALUES (LAST_INSERT_ID() + 1, "Hello")
AUTO_INCREMENT :
INSERT INTO table (field) VALUES ("Hello")
And the id is auto incrementing
Some documentation here :
https://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
https://dev.mysql.com/doc/refman/5.0/fr/example-auto-increment.html

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

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)