473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

multiple inserts and deletes

Hello all,

I'm using PHP/mySQL couple :) to insert and delete some informations
based on some criterium and I don't like to look at my code full of
FOR and IF's.

1)
Example: In a list of ID's 1 4 5 7 8 9 20 34 56 is possible to send an
UNIQUE command to mysql to delete the Id's 5, 7, 20, etc? Need I put a
ugly query like "Delete ... WHERE id=5 AND id=7 AND id=20" ad
infinitum?

2) How can I check without loops if a given value exist in the table?
Example: id's 1 3 5 7 8 must be inserted ONLY IF 3 or 5 doesn't exist.

Finally, It's very hard to do some search for examples to know how to
use the keyword "IN" , any hint please?

Thank you all and I'm sorry for the long post.
Jul 19 '05 #1
6 1437
baruch wrote:
1)
Example: In a list of ID's 1 4 5 7 8 9 20 34 56 is possible to send an
UNIQUE command to mysql to delete the Id's 5, 7, 20, etc? Need I put a
ugly query like "Delete ... WHERE id=5 AND id=7 AND id=20" ad
infinitum?
delete from tablename where id in(5,7,20);
2) How can I check without loops if a given value exist in the table?
Example: id's 1 3 5 7 8 must be inserted ONLY IF 3 or 5 doesn't exist.


# I'm not sure if you can do this with only one query,
# but with two queries
select * from table where id in(3,5);

# if previous didn't return any rows:
insert into yourtable(id) values(1),(3),(5),(7);
Jul 19 '05 #2
baruch wrote:
1)
Example: In a list of ID's 1 4 5 7 8 9 20 34 56 is possible to send an
UNIQUE command to mysql to delete the Id's 5, 7, 20, etc? Need I put a
ugly query like "Delete ... WHERE id=5 AND id=7 AND id=20" ad
infinitum?
delete from tablename where id in(5,7,20);
2) How can I check without loops if a given value exist in the table?
Example: id's 1 3 5 7 8 must be inserted ONLY IF 3 or 5 doesn't exist.


# I'm not sure if you can do this with only one query,
# but with two queries
select * from table where id in(3,5);

# if previous didn't return any rows:
insert into yourtable(id) values(1),(3),(5),(7);
Jul 19 '05 #3
baruch wrote:
1)
Example: In a list of ID's 1 4 5 7 8 9 20 34 56 is possible to send an
UNIQUE command to mysql to delete the Id's 5, 7, 20, etc? Need I put a
ugly query like "Delete ... WHERE id=5 AND id=7 AND id=20" ad
infinitum?
delete from tablename where id in(5,7,20);
2) How can I check without loops if a given value exist in the table?
Example: id's 1 3 5 7 8 must be inserted ONLY IF 3 or 5 doesn't exist.


# I'm not sure if you can do this with only one query,
# but with two queries
select * from table where id in(3,5);

# if previous didn't return any rows:
insert into yourtable(id) values(1),(3),(5),(7);
Jul 19 '05 #4
> delete from tablename where id in(5,7,20);
[..]

Thank you very much!
Jul 19 '05 #5
> delete from tablename where id in(5,7,20);
[..]

Thank you very much!
Jul 19 '05 #6
> delete from tablename where id in(5,7,20);
[..]

Thank you very much!
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stefan Kuhn | last post by:
Hi everybody, I want to establish replication between multiple (currently three) servers. Updates/inserts/deletes may happen on all of them. The idea I came up with was to do a...
3
by: kerri | last post by:
Hi, I need to do a mysqldump of specific inserts, updates & deletes. I read in the docs that I can use -w or --where. Can I do a join? Could someone provide an example? Is there another...
2
by: Joe | last post by:
Hey, I'm going to give some background on my situation in case anyone can point out a way around my problem altogether... for the problem itself, please skip to the bottom of the post. thanks....
4
by: bmccollum | last post by:
I have written a trigger that's supposed to go out and delete corresponding records from multiple tables once I delete a specific record from a table called tblAdmissions. This does not work and...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
5
by: Robert Brown | last post by:
Hi All. I have a routine that checks a SQL Table for all records 3 months prior to a predetermined date, then I insert them into an Archive DB then delete those records from the original table....
3
by: R.A.M. | last post by:
Please help. I have a table with single row. I need to allow only UPDATEs of the table, forbid INSERTs and DELETEs. How to achieve it? Thank you for information /RAM/
0
by: Benzine | last post by:
I recently rolled out replication on our production server (MS SQL 2000 SP4) and every time a subscriber tries to sync the following always appears in the Merge Agent History: "Downloaded 100...
0
by: Jankie | last post by:
Hey you all ! Happy holidays ! I have 2 tables: Ads ad_id primary ... ..
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.