![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hello, I'm trying to perform an INSERT .. but only if no rows in the table have a specific field that equals zero. For example: Nodes has the fields NodeID and ParentNodeID (there are more than that, but this is simplified) NodeID will be unique no matter what, since it is incremental. I want to INSERT INTO Nodes VALUES(NULL, 0) only if // There are no Nodes that have a ParentNodeID of 0 SELECT COUNT(NodeID) FROM Nodes WHERE ParentNodeID = 0 is less than 1 Thank you | |||
|
| Advertisements |
| | #2 | ||
| On Jun 25, 2:19 pm, evanp...@gmail.com wrote: > Hello, > > I'm trying to perform an INSERT .. but only if no rows in the table > have a specific field that equals zero. > > For example: > > Nodes has the fields NodeID and ParentNodeID (there are more than > that, but this is simplified) > > NodeID will be unique no matter what, since it is incremental. > > I want to > INSERT INTO Nodes > VALUES(NULL, 0) > > only if > // There are no Nodes that have a ParentNodeID of 0 > SELECT COUNT(NodeID) > FROM Nodes > WHERE ParentNodeID = 0 is less than 1 > > Thank you if not exists (select 1 from nodes where ParentNodeID = 0) begin insert into Nodes values(null, 0); end if; | |||
|
| Featured Websites | ||||
|
![]() |
| Tags: conditional, insert |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| unwanted insert delay | christopher@dailycrossword.com | Database | 0 | 07-01-2007 11:00 PM |
| INSERT QUERY WEIGHT | max@utm-appliance.com | Database | 2 | 07-01-2007 9:32 PM |
| conditional update | Tobin Harris | Database | 0 | 05-31-2007 8:40 PM |
| 'nested conditional' that can identify parent page? | Alan Jones | PHP | 8 | 05-20-2007 6:33 PM |
| help with posting using conditional if | Art | PHP | 3 | 05-20-2007 6:33 PM |
| Featured Websites | ||||
|