I'm working with some code. There are several queries whose effect is, if the row exists with some of the data filled in, then that row is updated with the rest of the data, and if the row does not exist, a new one is created. They look like this:
INSERT INTO table_name (col1, col2, col3)
SELECT %s AS COL1, %s AS COL2, %s AS COL3
FROM ...
I know of two ways to insert without duplication. The first is using a WHERE NOT EXISTS clause:
INSERT INTO table_name (col1, col2, col3)
SELECT %s, %s, %s
WHERE NOT EXISTS (
SELECT * FROM table_name AS T
WHERE T.col1 = %s
AND T.col2 = %s)
the other is doing a LEFT JOIN:
INSERT INTO table_name (col1, col2, col3)
SELECT ...
I'm still a neophyte when it comes to SQL queries, so I was hoping someone could lend me a hand.
Assume I have 3 tables, Skill, Set, and Contact, and 2 linking tables, SkillSet and ContactSet. (the 3 tables have an "ID" column that is being used as a primary key)
Contacts can have any number of sets, and vice versa (many-to-many)
Sets...
I have a situation where I want to insert a row if it doesn't exist, and to not insert it if it already does. I tried creating sql queries that prevented this from happening (see here), but I was told a solution is to create constraints and catch the exception when they're violated.
I have constraints in place already. My question is - ...
Following is the data and Select statement to work with :
declare @XMLdata xml
set @XMLdata = '
<taggroup key="pros" name="Le pour">
<tag isuseradded="false" count="1">Bonne qualité</tag>
<tag isuseradded="false" count="1">Correspond à mes attentes</tag>
<tag isuseradded="true" count="1">Impeccable</tag>
<ta...
i have a ADOQuery1 that is my master table and now i whant to use onother one ADOQuery2 for my detail Table but realy i don´t find the right way to work out the solucion.
ADOQuery1
nr- Autonum
name
local
quant.
ADOQuery2
Nro _ Autonum
name
l1
...
I have a table with two foreign keys in one table.
Table PROJECTS
- Id
- Owner - FK
- Client - FK
and
table USERS
- Id
- Name
I'd like to select all projects with appropriate names of the owner and client
The result should look like:
Id | OwnerName | ClientName
...
for example we have this xml:
<body>
<a>
<b>
<c>hello</c>
<c>world</c>
</b>
</a>
<a>
<b>
<c>another hello</c>
<c>world</c>
</b>
</a>
</body>
by Xpath query we can find all "B"-tags. But then w...
I have to tables, users and classes. I need to show the classes count of each user with user ID and i have to show those users as well .. with no classes. how to do it ..
...
Hello,
I am comparing two lists of email addresses in mysql - listA and listB (both of which are views). Originally, I wanted to find all of the email addresses in listA that are not in listB. I successfully accomplished that with:
$comparison_query = mysql_query("SELECT DISTINCT email_addresses FROM listA WHERE email_addresses NOT IN ...
My goal is to return a start and end date having same value in a column. Here is my table. The (*) have been marked to give you the idea of how I want to get "EndDate" for every similar sequence value of A & B columns
ID | DayDate | A | B
-----------------------------------------------
1 | 2010/07/1 | 200 | 300
2 | 2010/07/2 | 2...
I get the following error message when I try this query:
$query .= "($tid, {$_POST['type']['$i']}, 'Y', NOW())";
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near
(18, , 'Y', NOW())' at line 1
Everything in my code works except this line. I know ...
Hello,
I have 3 tables;
game, platform, game_platform
game
id name desc
---- ------------ ---------
1 Modern Warfare... Awesome game......
2 ... ...
3 ... ...
platform
id name
---- ------------
1 pc
2 ps3
3 ...
game_platform
game_id platform_i...
Hi guys,
Suppose I have a table like this:
hseid | projcode | bulidarea | room | hall | floor | totalfloor | price
0 | 1 | 100 | 1 | 1 | 9 | 25 | 100
1 | 2 | 99 | 1 | 1 | 9 | 25 | 100
2 | 2 | 101 | 1 | 1 | 9 | 25 | 100
3 | 4 | 110 | 1 | 1 | 9 | 25 | 100
4 | 3 | 130 | 1 | 1 | 9 | 25 | 100
5 | 1 | 95 | 1 | 1 | 9 | 25 | 100
6 | 4...
Hello!
Does somebodoy know query language DataLog ? Where I can find something about it ?I can'h find any tutorial on net :/
...
Hi all!
I need some help optimizing queries on 2 tables. One will contain about a million and the other will contain about 10 million of rows.
here is the table structure --
Table Structure
Sample Browse and Search Queries
These queries takes a very long time, about 15-20 secs, in some cases over a minute
So, please have a look an...
hi there,
i want to make a 'timeline' containing all mini blog posts from a user, and all the user he is following.
I want all these posts to be ordered by date..But how can i 'join' the posts, because the 'following' relation is in another table, so i have to make some kind of a join between the two tables, for taking the data.
For no...
Hi.
I have three tables:
player [id, name]
attribute [id, name]
player_attribute [id, player_id, attribute_id, value]
each player can have different attributes, some of them don't have any. Now I need to search for players with certain attributes, e.g. all players that have number 11, and their first name is John. At this moment I al...
I have a table with attributes like this:
likes(id, message, ip, time)
id is the primary key and is auto-incrementing. Whet I want to do is select 30 rows from this table based on an id that I provide.
I can build a random array of all IDs I want to grab from the table, now I just need to go about doing that. My usual SQL query would...
I have an indexed object with three fields (userId, title, description). I want to find all objects of a specific user where the title OR the description contains a given keyword.
I have something like this (but that's obviously wrong):
WildcardQuery nameQuery = new WildcardQuery(new Term("name", filter.getSearch()));
WildcardQuery des...