exists

INSERT IF NOT EXISTS ELSE UPDATE?

一笑奈何 提交于 2019-11-26 03:22:09
问题 I\'ve found a few \"would be\" solutions for the classic \"How do I insert a new record or update one if it already exists\" but I cannot get any of them to work in SQLite. I have a table defined as follows: CREATE TABLE Book ID INTEGER PRIMARY KEY AUTOINCREMENT, Name VARCHAR(60) UNIQUE, TypeID INTEGER, Level INTEGER, Seen INTEGER What I want to do is add a record with a unique Name. If the Name already exists, I want to modify the fields. Can somebody tell me how to do this please? 回答1: Have

SQL - IF EXISTS UPDATE ELSE INSERT INTO

◇◆丶佛笑我妖孽 提交于 2019-11-26 03:07:57
问题 What I\'m trying to do is INSERT subscribers in my database, but IF EXISTS it should UPDATE the row, ELSE INSERT INTO a new row. Ofcourse I connect to the database first and GET the $name , $email and $birthday from the url string. $con=mysqli_connect(\"localhost\",\"---\",\"---\",\"---\"); // Check connection if (mysqli_connect_errno()) { echo \"Failed to connect to MySQL: \" . mysqli_connect_error(); } $name=$_GET[\'name\']; $email=$_GET[\'email\']; $birthday=$_GET[\'birthday\']; This works

How to check if mysql database exists

拥有回忆 提交于 2019-11-26 02:16:20
问题 Is it possible to check if a (MySQL) database exists after having made a connection. I know how to check if a table exists in a DB, but I need to check if the DB exists. If not I have to call another piece of code to create it and populate it. I know this all sounds somewhat inelegant - this is a quick and dirty app. 回答1: SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'DBName' If you just need to know if a db exists so you won't get an error when you try to create it,

How to check if element exists in the visible DOM?

吃可爱长大的小学妹 提交于 2019-11-26 00:56:43
问题 How do you test an element for existence without the use of the getElementById method? I have setup a live demo for reference. I will also print the code on here as well: <!DOCTYPE html> <html> <head> <script> var getRandomID = function (size) { var str = \"\", i = 0, chars = \"0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ\"; while (i < size) { str += chars.substr(Math.floor(Math.random() * 62), 1); i++; } return str; }, isNull = function (element) { var randomID =

Select rows which are not present in other table

这一生的挚爱 提交于 2019-11-25 23:57:25
问题 I\'ve got two postgresql tables: table name column names ----------- ------------------------ login_log ip | etc. ip_location ip | location | hostname | etc. I want to get every IP address from login_log which doesn\'t have a row in ip_location . I tried this query but it throws a syntax error. SELECT login_log.ip FROM login_log WHERE NOT EXIST (SELECT ip_location.ip FROM ip_location WHERE login_log.ip = ip_location.ip) ERROR: syntax error at or near \"SELECT\" LINE 3: WHERE NOT EXIST (SELECT

Best way to test if a row exists in a MySQL table

前提是你 提交于 2019-11-25 23:14:06
问题 I\'m trying to find out if a row exists in a table. Using MySQL, is it better to do a query like this: SELECT COUNT(*) AS total FROM table1 WHERE ... and check to see if the total is non-zero or is it better to do a query like this: SELECT * FROM table1 WHERE ... LIMIT 1 and check to see if any rows were returned? In both queries, the WHERE clause uses an index. 回答1: You could also try EXISTS : SELECT EXISTS(SELECT * FROM table1 WHERE ...) and per the documentation, you can SELECT anything.

【MySQL】多表查询 -- 2019-08-07 12:53:19

╄→尐↘猪︶ㄣ 提交于 2019-11-25 23:05:36
原创: http://106.13.73.98/__/26/ 目录 多表链接查询 笛卡尔积 内链接 inner join 外链接之左链接 left join 外链接之右链接 right join 全外链接 符合条件链接查询 子查询 先准备两张表:部门表(department)、员工表(employee) # 部门表create table department( id int primary key auto_increment, name varchar(20) not null ); # 员工表create table employee( id int primary key auto_increment, name varchar(20) not null, sex enum('male', 'female') not null default 'male', age int not null, dep_id int not null ); # 插入数据insert into department values(200, "技术"),(201, "人力资源"),(202, "销售"),(203, "运营"); insert into employee(name, sex, age, dep_id) values('egon', 'male', 18, 200),('alex'

SQL Server IN vs. EXISTS Performance

前提是你 提交于 2019-11-25 22:46:22
问题 I\'m curious which of the following below would be more efficient? I\'ve always been a bit cautious about using IN because I believe SQL Server turns the result set into a big IF statement. For a large result set, this could result in poor performance. For small result sets, I\'m not sure either is preferable. For large result sets, wouldn\'t EXISTS be more efficient? WHERE EXISTS (SELECT * FROM Base WHERE bx.BoxID = Base.BoxID AND [Rank] = 2) vs. WHERE bx.BoxID IN (SELECT BoxID FROM Base

Check if multiple strings exist in another string

末鹿安然 提交于 2019-11-25 21:57:48
问题 How can I check if any of the strings in an array exists in another string? Like: a = [\'a\', \'b\', \'c\'] str = \"a123\" if a in str: print \"some of the strings found in str\" else: print \"no strings found in str\" That code doesn\'t work, it\'s just to show what I want to achieve. 回答1: You can use any: if any(x in str for x in a): Similarly to check if all the strings from the list are found, use all instead of any . 回答2: any() is by far the best approach if all you want is True or False

【MySQL】多表查询 -- 2019-08-07 09:53:56

那年仲夏 提交于 2019-11-25 19:24:08
原创: http://106.13.73.98/__/26/ 目录 多表链接查询 笛卡尔积 内链接 inner join 外链接之左链接 left join 外链接之右链接 right join 全外链接 符合条件链接查询 子查询 先准备两张表:部门表(department)、员工表(employee) # 部门表create table department( id int primary key auto_increment, name varchar(20) not null ); # 员工表create table employee( id int primary key auto_increment, name varchar(20) not null, sex enum('male', 'female') not null default 'male', age int not null, dep_id int not null ); # 插入数据insert into department values(200, "技术"),(201, "人力资源"),(202, "销售"),(203, "运营"); insert into employee(name, sex, age, dep_id) values('egon', 'male', 18, 200),('alex'