Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 478 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert into a MySQL table or update if exists

#11
Any of these solution will work regarding your question:


INSERT IGNORE INTO table (id, name, age) VALUES (1, "A", 19);

or

INSERT INTO TABLE (id, name, age) VALUES(1, "A", 19)
ON DUPLICATE KEY UPDATE NAME = "A", AGE = 19;

or

REPLACE INTO table (id, name, age) VALUES(1, "A", 19);




Reply

#12
## Following are some of the possible approaches:

### Using `INSERT INTO`
The [`INSERT`][1] statement allows you to insert one or more rows into a table

* First, specify the table name and a list of comma-separated columns inside parentheses after the `INSERT INTO` clause.
* Secondly, put a comma-separated list of values of the corresponding columns inside the parentheses following the `VALUES` keyword.
```sql
INSERT INTO table_name(column_name1, column_name2, column_name3) VALUES("col_value_1", "col_value_2", "col_value_3");
```


### Using `INSERT INTO` with `WHERE NOT EXISTS` clause

```sql
INSERT INTO table_name (column_name_1, column_name_2, column_name_3)
SELECT * FROM (SELECT "col_value_1", "col_value_2","col_value_3") AS tmp_name
WHERE NOT EXISTS (
SELECT column_name2 FROM table_name WHERE column_name = "sample_name"
) LIMIT 1;
```

### Using `REPLACE INTO`

[`REPLACE`][2] works exactly like [`INSERT`][1], except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.

```sql
REPLACE INTO table_name(column_name1, column_name2, column_name3) VALUES("col_value_1", "col_value_2", "col_value_3");
```


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#13
Check out [`REPLACE`](

[To see links please register here]

):

> `REPLACE` works exactly like `INSERT`, except that if an old row in the table has the same value as a new row for a `PRIMARY KEY` or a `UNIQUE` index, the old row is deleted before the new row is inserted.

Example:

REPLACE INTO `tablename` (`id`, `name`, `age`) VALUES (1, "A", 19)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through