query

Why am I getting this SQL/DB error?

Hey everyone, I am trying to run a simple SQL statement with DB2 and am having a few problems. I would like to have a single script in a txt/db2 file and have the engine process all of the commands Here is the script: CONNECT TO MYDB CREATE TABLE PERSONS( PID SMALLINT NOT NULL, NAME VARCHAR(20) NOT NULL ) TERMINATE When ...

How to give entry in the where clause when we use it in webpages?

According to the user's input I want to select the record from the database. This is my code: <% String jempid=request.getParameter("empid"); out.println(jempid); int intempid=1223; Connection conn=null; String url="jdbc:mysql://localhost/employees"; Class.forName("com.mysql.jdbc.Driver").newInstance(); conn=DriverManager.getConnection...

Weird SQL issue

I have a really weird issue with an SQL query I've been working with for some time. I'm using SQL Server 2005. Here's an example table from which the query is made: Log: Log_ID | FB_ID | Date | Log_Name | Log_Type 7 | 4 | 2007/11/8 | Nina | Critical 6 | 4 | 2007/11/6 | John | Critical 5 | 4 |...

How can I query my subversion repository?

Currently I would simply like to find all files that have not been modified in the last X days but ultimately I would like to be able to make more complex queries against my subversion repository. Is there a Subversion Query Language of some sort or an API that I could use? ...

Query to fetch MsSQL table unique index and primary keys

SELECT sysobjects.xtype, syscolumns.name, sysindexkeys.indid, sysobjects.type FROM syscolumns LEFT JOIN sysobjects ON syscolumns.id = sysobjects.id LEFT JOIN sysindexkeys ON ( syscolumns.id = sysindexkeys.id AND syscolumns.colid = sysindexkeys.colid ) WHERE sysobjects.name = '{$table}' AND sysindexkeys.indid IS NOT NULL ORDER BY...

SQL query: Delete all records from the table except latest N?

Is it possible to build a single mysql query (without variables) to remove all records from the table, except latest N (sorted by id desc)? Something like this, only it doesn't work :) delete from table order by id ASC limit ((select count(*) from table ) - N) Thanks. ...

How to randomly select rows in SQL??

In my db, I have a table "customerNames" which has two columns "Id" and "Name" and approx. 1,000 results. I am creating a functionality where I have to pick up the 5 customers randomly every time. Can anyone tell me how to create a query which will get random 5 rows (Id, and Name) every time when query is executed. edited I am using M...

How to use INNER JOIN in the scenario?

I have 2 tables: 'Users' Table id username ---- -------- 0001 user1 0002 user2 0003 user3 0004 user4 'Friends' Table user_id friend_id friend ------- --------- ------ 0001 0004 1 0002 0004 1 0005 0004 0 How do I display all user4 friends'...

Can I merge two MySQL queries into one?

I had the following code <?php $getFriendQuery = "SELECT DISTINCT U.username FROM users as U INNER JOIN test_friends as F on U.Id = F.user_id WHERE F.friend_id = '{$userID}' && F.active=1"; $getFriendResult = mysql_query($getFriendQuery, $conn) or die (mysql_error()); $friendName = ""; while($getFriendFetch = mysql_fetch_assoc($ge...

SQL Structure to Store Surveys and Answers - Build Tables and Queries Based on User Data?

I'm a total newbie when it comes to SQL. I'm making a site in ASP.NET for doing surveys. A privileged admin user will be able to build a survey. Then lots of other people will respond to the survey. Once I have the set of questions for a new survey, what is the best way to automatically construct a table and an INSERT query to store t...

mssql_query accent

I hava a problem with this mssql_query in PHP : $query = 'SELECT Ville FROM tblLstManufacturiers where province = "Québec"'; The result is empty because I have an accent in Québec How can I do this? ...

LINQ - Add property to results

Is there a way to add a property to the objects of a Linq query result other than the following? var query = from x in db.Courses select new { x.OldProperty1, x.OldProperty2, x.OldProperty3, NewProperty = true ...

Is it possible in SQL to match a LIKE from a list of records in a subquery?

Using these tables, as a sample: Table CodeVariations CODE ----------- ABC_012 DEF_024 JKLX048 And table RegisteredCodes CODE AMOUNT -------- ------ ABCM012 5 ABCK012 25 JKLM048 16 Is it possible to write a query to retrieve all rows in RegisteredCodes when CODE matches a pattern in any row of the Cod...

Checking sqlite query results

How do I check if an sqlite query returned anything before I stop looping through results. //see if there are results and do something if not while(sqlite3_step(selectstmt) == SQLITE_ROW) { /*process on reults */} ...

Tips for improving this slow mysql query?

I'm using a query which generally executes in under a second, but sometimes takes between 10-40 seconds to finish. I'm actually not totally clear on how the subquery works, I just know that it works, in that it gives me 15 rows for each faverprofileid. I'm logging slow queries and it's telling me 5823244 rows were examined, which is odd...

Add 2 hours to current time in MySQL?

Which is the valid syntax of this query in MySQL? SELECT * FROM courses WHERE (now() + 2 hours) > start_time *note: start_time is a field of courses table* ...

Recordset in VBA and C sharp

considering this code Dim cn As New ADODB.Connection, cn2 As New ADODB.Connection Dim rs As ADODB.Recordset Dim connString As String Dim SelectFieldName Set cn = CurrentProject.Connection SelectFieldName = astrField...

Search for a string in an all the tables, rows and columns of a DB

I am lost in a big database and I am not able to find where the data I get comes from. I was wondering if it is possible with SQL Server 2005 to search for a string in an all the tables, rows and columns of a DB? Does anybody has an idea if it is possible and how? Thanks! ...

Best way to query back unique attribute values in a javascript array of objects?

What would be the best (or fastest) way to find all the possible values of "foo" in the following example array. var table = [ {foo: 0, bar:"htns", stuff:123}, {foo: 2, bar:"snhn", stuff:156}, {foo: 5, bar:"trltw", stuff:45}, {foo: 5, bar:"lrctm", stuff:564}, //few thousand lines later {foo: 2596, bar:"cns", stuf...

How do you count the related rows within a query.

I am trying to make a query that pulls out all Tickets for a particular company. Within that table will be a column named [Repeat] What I need the query to do is check to see if there are any other rows that have a matching Circuit_ID within the last 30days of that ticket. "SELECT [MAIN_TICKET_ID], [CompID], [ActMTTR], [ActOTR], [DtCr]...