query

How can a query return only one random row for each distinct column?

I've a table with two columns, say, column1 and column2. Column2 is not unique. For each distinct value of column2, I want a random row, only one row, from the table? i.e. my result set should have as many rows as the number of distinct values of column2. eg: column1 column2 x 1 y 2 z 1 I want the result to...

Does MySQL's LIMIT keyword guarantee order of returned data?

I am new to MySQL, but I have used Oracle for some time. I am a little confused about MySQL's LIMIT keyword. Does this keyword imply that the order of the returned data will be the same every time the query is executed? What if more data is added to the tables that affect the query? And how would the data be ordered if no order-by clause...

retrieve specific range of rows in a SQL Server table

Hello everyone, I have a table structure like (OrderID [uniqueidentifier], OrderDesciption [nvarchar]), I am using ADO.Net + C# + VSTS 2008 + SQL Server 2008. The table is big, and I want to let client give me two inputs, begin range index and end range index, and I will return specific rows of the table which is in the range (between b...

C# Sql Compact text query on binary column

I was wondering if anyone knew how to compile a text query for sql compact that goes like this : command.CommandText = "SELECT * FROM tableName WHERE id = binary_Data" The id column is a 32 byte binary column that is indexed and "binary_Data" is the binary data to compare to, but I am not sure how to get a "binary_Data" into the text ...

Why does SQLyog returns MySQL query results 10x faster than my Delphi program?

select rectype,jobid,jobrecid,template,assignedto,entereddt,enteredby,ref1,processed,processeddt, processbydt,title,description,connectlanhandle,finished,updateddt,ref2,cancelled, requireaccept,acceptrejectstate,acceptrejectbydt,alert1dt,alert2dt,alert3dt,despatchallowed, flag,ref3,projectid,duration,skillset,postcode,prefschedulefrom,pr...

Oracle DB: How can I write query ignoring case?

Hello, As I had written in title, I have SQL query, run on Oracle DB, lets say: SELECT * FROM TABLE WHERE TABLE.NAME Like 'IgNoReCaSe' If I would like, that the query would return either "IGNORECASE", "ignorecase" or combinations of them, how can this be done? Is this possible? ...

How to write LDAP query to test if user is member of a group?

I want to write an LDAP query which tests whether a user (sAMAccountName) is a member of a particular group. Is it possible to do that so that I get either 0 or 1 result records? I guess I can get all groups for the user and test each one for a match but I was wondering if I could pack it into one LDAP expression. Any ideas? Thanks ...

Best way to achieve exclusion matrix via query.

What is the best way to achieve this exclusion matrix via query. There are fixed number of products in a table and idea is if a product is sold to a customer (represented by row), the other products (columns) may or may not be sold based on the rule matrix below. The aim is to get products code which are allowed to sold for any given s...

linq over strings C#

Hello! Could someone please give an example of how to use ling to query over a long string of text and find a substring within that string? regards ...

Intercept and Rewrite Queries in SQL Server 2005

We have an application built on top of SQL server 2005 that we have no control over. We've recently discovered that this application is sending some very inefficient SELECT queries to SQL that is causing serious capacity issues on the database. I know the right solution is to crack open the code for the application and change the queries...

how to concatenate uniqueidentifier in a dynamic query

I have a dynamic query in which I want to concatenate uniqueidentifier, but + and & operators are not supporting this, is there a way I can concatenate uniqueidentifier to a dynamic string. Any sample or any help in this regard will be highly appricated. ...

Most Efficient MySQL query to update a table from identical memory table

I'm implementing a memory cache for a table that looks like this (simplified): Item1 (integer), Item2 (integer), cnt (Integer) The original table includes millions of pairs like this. and it updates rapidly. To make it all more efficient I want to write new pairs to an identical memory table and update the real table on disk periodica...

Datatype conversion in IBM DB2

I'm writing a query to do some stuff. But its not working the way I want it to: select CORR_ID from TABLE1 where CORR_ID not in (select id from TABLE2) The problem is, TABLE2.id is a long, while TABLE1.CORR_ID is a string. So how can I make it work? PS: I'm using IBM UDB. ...

What is the most efficient way to create an order count summary by hour, day, month in SQL Server 2005?

Given a table: create table #orders ( orderid int, orderdatetime datetime ) What is the best way to write sql to output a report containing the count of orders from the current and previous 24 hours, total orders for the current day and previous 7 days, total orders for the current week and previous 4 weeks, and total orders f...

subsonic generate invalid JOIN query

Hello, I'm new to SobSonic and trying to create a join query for two tables. I found the options LeftInnerJoin, which generate the query that seems valid. When trying to run it on MSSQL 2005, it does not work since LEFT INNER JOIN is not valid, but LEFT JOIN. and I'm still looking for way to generate query for joining mutiples tables an...

SQL Query Distinct Column Concatenate Other Column

Hi All, I have a MS SQL query that joins multiple tables and an example of the results are: EmailAddress Column2 --------------------- ---------------- [email protected] Value1 [email protected] Value2 [email protected] Value5 What I reall...

TSQL: Select from set of columns with lowest positive value

Example Schema: RowID Quantity ModifiedPrice GroupPrice CustomPrice SalePrice ---------------------------------------------------------------------------- 1 5 20.00 0 15.00 17.00 2 2 14.00 7.00 22.00 0 3 9 10.00...

Loop through multi dimension array to show grid in PHP

I have 3 tables. Apls, Hulls and AplsHulls. Apls consists of id, name, date Hulls consists of id, production_name AplsHulls is a join table and consists of id, apl_id, hull_id, status. Not every Hull is associated with each Apl. The ones that are are in the join table with a status (shipped,in production, etc.) I need to display a rep...

Return Data and Type of mysql_fetch_array()

Consider the following 3 standard statements $queryString = "SOME SQL SELECT QUERY"; $queryResult = mysql_query($queryString); $queryArray = mysql_fetch_array($queryResult); Question is : If the result set of the query is empty, what will be the resultant datatype and value of $queryArray after all three statements are executed ? ...

sql async query problem....

So, why doesn't this ever make it to the callback function? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace sqlAsyncTesting { public partial class Form1 : F...