query

Replacing characters with specified one

Hello All, I have a string as follows - MFMFMF now i want to change this string to FMFMFM how to do this , help needed pls i had tried select replace(replace('mfmfmf','M','F'),'F','M') this gives me result - MMMMMM which i donot what i want the output to be FMFMFM Need your help D.Mahesh ...

When is a query too big?

Hey guys, I'm monitoring calls and putting them into a database. I'm putting caller, called, start, end in database. There are an average of 70-80 calls a day (none in the weekend), so it comes to 350-400 a week. The program will be used for a long time, so after a year there will be many items in the database. A part of the program s...

How do I add a record only if it doesn't already exist in SQL Server?

Hi, I have a project in C# with a Sql-server Database. In that database I have a table named 'Process' and columns named 'process_name', 'Full_Name' and 'Version' (all of the type:nvarchar(50)). I want to write a query wich will add the new process, only if it doesn't exist in the table yet. How can I do that? Many thanks, ...

Parameterized SQL statements vs. very simple method

When I started to write the first SQL-Statements in my programs I felt quite comfortable with protecting myself against SQL-Injection with a very simple method that a colleague showed me. It replaced all single quotes with two single quotes. So for example there is a searchfield in which you can enter a customername to search in the cus...

What happens if you kill a long-running alter query?

What happens if you kill a long-running alter query? Will the alter query simply revert? How long could that take (as a proportion of the time it has already been running)? What if that query is being replicated onto another server? Will killing the process on the other server revert the original server's alter query? We're running mys...

Conditionally Summing the same Column multiple times in a single select statement?

I have a single table that shows employee deployments, for various types of deployment, in a given location for each month: ID | Location_ID | Date | NumEmployees | DeploymentType_ID As an example, a few records might be: 1 | L1 | 12/2010 | 7 | 1 (=Permanent) 2 | L1 | 12/2010 | 2 | 2 (=Temp) 3 | L1 | 12/2010 | 1 | 3 (=Support) 4 ...

Tournament bracket

Not sure of the best way to go about this? I want to create a tournament bracket of 2,4,8,16,32, etc teams. The winner of the first two will play winner of the next 2 etc. All the way until there is a winner. Like this Can anyone help me? OK so more information. Initially I want to come up with a way to create the tournament with the...

SQL Query to duplicate records based on If statement

Hi, I'm trying to write an SQL query that will duplicate records depending on a field in another table. I am running mySQL 5. (I know duplicating records shows that the database structure is bad, but I did not design the database and am not in a position to redo it all - it's a shopp ecommerce database running on wordpress.) Each pro...

MySQL top count({column}) with a limit

I have a table with an ip address column. I would like to find the top five addresses which are listed. Right now I'm planning it out the following: Select all distinct ip addresses Loop through them all saying count(id) where IP='{ip}' and storing the count List the top five counts. Downsides include what if I have 500 ip addresses...

SQL Server query replace for MySQL Instruction

Hi, I'm new to SQL Server, and used mysql for a while now... SELECT A.acol, IF(A.acol<0,"Neg","Pos") as Column2 From Table I want to do something like that on SQL Server, but there doesn't exist the IF instruction. How do I replace that if, in a SQL Server 2008 Query? ...

MySQL Query problem in CodeIgniter

So I'm using the following: $r = new Record(); $r->select('ip, count(*) as ipcount'); $r->group_by('ip'); $r->order_by('ipcount', 'desc'); $r->limit(5); $r->get(); foreach($r->all as $record) { echo($record->ip." "); echo($record->ipcount." <br />"); } Standard: SELECT `ip`, count...

SQL query for the latest record for each day

I've got an Oracle 10g database with a table with a structure and content very similar to the following: CREATE TABLE MyTable ( id INTEGER PRIMARY KEY, otherData VARCHAR2(100), submitted DATE ); INSERT INTO MyTable VALUES (1, 'a', TO_DATE('28/04/2010 05:13', ''DD/MM/YYYY HH24:MI)); INSERT INTO MyTable VALUES (2, '...

MySQL: Request to select the last 10 send/received messages to/by different users

I want to select the 10 last messages you received OR you sent TO different users. For example the results must be shown like that: 1. John1 - last message received 04/17/10 3:12 2. Thomy - last message sent 04/16/10 1:26 3. Pamela - last message received 04/12/10 3:51 4. Freddy - last message received 03/28/10 9:00 5. Jack - las...

In PHP + MySQL, How do I join many tables with conditions

Hi, I'm trying to get the users full activity throughout the website. I need to Join many tables throughout the database, with that condition that it is one user. What I currently have written is: SELECT * FROM comments AS c JOIN rphotos AS r ON c.userID = r.userID AND c.userID = '$defineUserID'; But What it is returning is ever...

Time calculations with MySQL TIMEDIFF

Hi there, I have the following table: mysql> SELECT id,start1,stop1,start2,stop2 FROM times; +----+---------------------+---------------------+---------------------+---------------------+ | id | start1 | stop1 | start2 | stop2 | +----+---------------------+---------------------+----...

using union in a construct sparql query

hello, i have such a sparql query: select ?s ?p ?o from <http://localhost:8890/DAV/ranking&gt; where { {<http://seekda.com/providers/cdyne.com/PhoneNotify&gt; so:hasEndpoint ?s. ?s ?p ?o} union {<http://seekda.com/providers/cdyne.com/PhoneNotify&gt; ?p ?o} } but i need a graph query (construct ord describe). unfortunatly i have no...

SQL Server > Query > Column Names

Hi, I'm here again- I have something like this Select A.a, A.b, A.a+A.b as c, (A.a+A.b*2)+A.d as d from Table But i want to know, if it is possible, to make it work with something like this: Select A.a,A.b,A.a+A.b as c, (c*2)+A.d as d from Table Thank you ...

Can't get SubSonic insert to work

I'm trying to insert a record into a table without using the SubSonic object in a VB.Net Windows app. (It will take too long to explain why.) Dim q As New SubSonic.Query("tablename") q.QueryType = SubSonic.QueryType.Insert q.AddUpdateSetting("Description", txtDescription.Text) q.Execute() This just updates all the rows in the table. I ...

Query for props list with or without values

Hi, I'm trying to make a SELECT on three relational tables like these ones: table_materials -> material_id - material_name table_props -> prop_id - prop_name table_materials_props - row_id -> material_id -> prop_id - prop_value On my page, I'd like to get a result like this one but i have some problem with the query: material pr...

SQL Server, how to join a table in a "rotated" format (returning columns instead of rows)?

Sorry for the lame title, my descriptive skills are poor today. In a nutshell, I have a query similar to the following: SELECT P.LAST_NAME, P.FIRST_NAME, D.DEMO_GROUP FROM PERSON P JOIN PERSON_DEMOGRAPHIC PD ON PD.PERSON_ID = P.PERSON_ID JOIN DEMOGRAPHIC D ON D.DEMOGRAPHIC_ID = PD.DEMOGRAPHIC_ID This returns output like this: LAST_N...