query

Quickly or concisely determine the longest string per column in a row-based data collection

Judging from the result of my last inquiry, I need to calculate and preset the widths of a set of columns in a table that is being made into an Excel file. Unfortunately, the string data is stored in a row-based format, but the widths must be calculated in a column-based format. The data for the spreadsheets are generated from the follow...

Is there a way to select nth column in a SELECT clause from a table/view

I've this GIGANTIC view with several hundred columns and I need to select 114th column something like: SELECT "144" FROM MyView; PS: Obviously, I don't know the name of the column. I just copied the results row into an Excel file, searched for a particular value that is in EJ column so I want to select all rows showing only nth column...

SQL - re-arrange a table via query

I have a poorly designed table that I inherited. It looks like: User Field Value ------------------- 1 name Aaron 1 email [email protected] 1 phone 800-555-4545 2 name Mike 2 email [email protected] 2 phone 777-123-4567 (etc, etc) I would love to extract this ...

How a query without filtration values is called? "empty query" ?

Hi, you know, a query that shows all the registers of a table. Javi ...

SQL query: Last but one rank for user

My table structure looks like this: create table rankings ( id IDENTITY NOT NULL, user_id INT NOT NULL, game_poule_id INT NOT NULL, rank INT NOT NULL, insertDate DATETIME NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (game_poule_id) REFERENCES game_poules(id) ON DELETE CA...

Symfony and Doctrine 1.2.2: How can i get the SQL clause of a Doctrine_Query object?

Hi, i have this code: $this->lista_miembros = $this->filtro->buildQuery($valores_query); var_dump($this->lista_miembros); var_dump outputs a Doctrine_Query object: object(Doctrine_Query)[121] protected '_subqueryAliases' => array I tried getSql() ... $q = Doctrine_Query::create() ->select('u.id') ->from('U...

The explain tells that the query is awful (it doesn't use a single key) but I'm using LIMIT 1. Is this a problem?

The explain command with the query: explain SELECT * FROM leituras WHERE categorias_id=75 AND textos_id=190304 AND cookie='3f203349ce5ad3c67770ebc882927646' AND endereco_ip='127.0.0.1' LIMIT 1 The result: id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE ...

How to Get A Joined Query to List Object

I have a dynamic sql query which contains more than one table joined. Normally I get this query to a datatable and use it. For now I want to get result of this query to a list object. Does anyone help me about this case? ...

Jdbc Template and MySql interaction for Frequently Changing Queries

There are some queries used by a DAO layer that is implemented in JDBC Template String longQuery = "....."; public List<AnObject> findObjectsBySomething(Something s) { return getJdbcTemplate().queryForObjects(longQuery, myRowMapper, s); } longQuery is going to frequently change, but I don't want to have to manage it right in the s...

ColdFusion Timeout Error

I have a scheduled task that runs once a day that builds an XML file that I pass off to another group. Recently the amount of data has greatly increased and is now causing the task to time out (I think). I have tried to optimize my script as much as possible but with no luck. It times out long before an hour and I don't get any kind of C...

Is there a way to split the results of a select query into two equal halfs?

I need a solution for a select query in Sql Server 2005. I'd like to have a query returning two ResultSets each of which holding exactly half of all records matching a certain criteria. I tried using TOP 50 PERCENT in conjunction with an Order By but if the number of records in the table is odd, one record will show up in both resultset...

SQL select statement from 2 tables

Hi, I have a small sql question. I have 2 tables Members and Managers Members has: memberID, Name, Address Managers has: memberID, EditRights, DeleteRights EditRights and DeleteRights are of type bit. Mangers have a relationship with Members, because they are members themselves. I want to select all members id's, name and adress a...

SQL conditional Pivot

Yes, this is another Pivot question... I've read through nearly all the previous questions and I can't seem to hack together a query that does what I need. Here is what my table looks like: FirmName Account Balance Pmt Revolving Installment Mortgage Amex 12345 10000 2000 1 0 0 Discover 54321 20000 4000 ...

How do I construct a Django reverse/url using query args?

I have URLs like http://example.com/depict?smiles=CO&amp;width=200&amp;height=200 (and with several other optional arguments) My urls.py contains: urlpatterns = patterns('', (r'^$', 'cansmi.index'), (r'^cansmi$', 'cansmi.cansmi'), url(r'^depict$', cyclops.django.depict, name="cyclops-depict"), I can go to that URL and get...

SQL query to get latest record for all distinct items in a table

I have a table of all sales defined like: mysql> describe saledata; +-------------------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------------+---------------------+------+-----+---------+-------+ | SaleDate | datetime | N...

How to use dojo-tree node in php query

Hi, could someone explain how it is possible to extract a node label (instead of a value) from a dojo-tree and than use it in a (php) query? Thank you! ...

SQLite Query to Insert a record If not exists

I want to insert a record into a sqlite table if its actually not inserted. Let's say it has three fields pk, name, address I want to INSERT new record with name if that name not added preveously. Can we do with this in a single Query. Seems like its slightly different from SQL Queries sometimes. ...

TSQL Help (SQL Server 2005)

I have been playing around with a quite complex SQL Statement for a few days, and have gotten most of it working correctly. I am having trouble with one last part, and was wondering if anyone could shed some light on the issue, as I have no idea why it isnt working: INSERT INTO ExistingClientsAccounts_IMPORT SELECT DISTINCT cca.Accoun...

How to access java collection, just like the table in the database, having indexes and LINQ-like query's

This task occurs from time to time in my projects. I need to handle a collection of some complex elements, having different attributes, such as login, password_hash, role, etc. And, I need to be able to query that collection, just like I query a table in the database, having only partial data. For example: get all users, with role "user"...

Hibernate CreateSQL Query Problem

Hello All I'm trying to use hibernates built in createsql function but it seems that it doesn't like the following query. List =hibernateSession.createSQLQuery("SELECT number, location FROM table WHERE other_number IN (SELECT f.number FROM table2 AS f JOIN table3 AS g on f.number = g.number WHERE g.other_number = " + var + ") ORDER...