query

Get primary key of aggregated, group by SQL query using PostgreSQL

Hi, I'm struggling with creating a SQL query involving aggregates using PostgreSQL. Consider the following tables: CREATE TABLE thing ( id INT NOT NULL PRIMARY KEY, price NUMERIC(10,2) NOT NULL, description VARCHAR(255) NOT NULL, url VARCHAR(255) NOT NULL, location_id INT NOT NULL REFERENCES location(id) ) CREATE TABLE locat...

SQL query join elements

Hi guys. I will re-write my doubt to be more easy to understand. I have one table named SeqNumbers that have only one collumn of data named PossibleNumbers, that has value from 1 to 10.000. Then I have another Table named Terminals and one of the collumns have the serial numbers of the terminals. What I want is get all the SerialNumbers ...

Oracle - how to remove white spaces?

I am running this statement: select trim(a),trim(b) from table x; Even though I used the trim() statement, my output looks like this: A B ___ ____ kunjramansingh ...

Most efficient way to match a certain number of items in a db.Model ListProperty

In reference to this different but not unrelated question I will borrow the example models. class Foo(db.Model): bars = db.ListProperty(db.Key) class Bar(db.Model): pass If I have a certain Foo entity and I want to get all of the other foo entities also containing a certain bar Key in its bars ListProperty, I would use the following...

When is it considered too much for using strings in a MySQL IN clause?

Please tell me from experience with using the "IN clause" in a MySQL query is considered to be too large of a list to push through to be considered good practice? Example scenario is I have a string of user ID numbers that I will pull from a cache, it can range from anywhere from 1 number all the way up to being 5,000 numbers in this ...

Is it possible to have 2 limits in a MySQL query?

Ok here is the situation (using PHP/MySQL) you are getting results from a large mysql table, lets say your mysql query returns 10,000 matching results and you have a paging script to show 20 results per page, your query might look like this So page 1 query SELECT column FROM table_name WHERE userId=1 AND somethingelse=something else...

Mysql Sub-Select Problem

Hi, I have two queries to get related tags from a mysql database, one works, one does not, my question is: "why?" Problem: When executing the first query, the mysql server gets 100% cpu usage, and has to be restarted to function again. Query 1 (does not work): SELECT tags.*, COUNT(ct.company_id) AS count FROM company2tag ct, tags WHE...

How to optimize MySQL query (group and order)

Hey all, I've got a query in need of optimizing. It works but its a dog, performance wise. It reads like this: SELECT * FROM ( SELECT * FROM views WHERE user_id = '1' ORDER BY page DESC ) v GROUP BY v.session I'm tracking views to different pages, and I want to...

Pull back rows from multiple tables with a sub-select?

I have a script which generates queries in the following fashion (based on user input): SELECT * FROM articles WHERE (articles.skeywords_auto ilike '%pm2%') AND spubid IN ( SELECT people.spubid FROM people WHERE (people.slast ilike 'chow') GROUP BY people.spubid) LIMIT 1; The resulting data set: Array ( [0] => Ar...

Need help with sql server query

I have a table in SQL Server 2005 with the following structure: fname | id ---------- aaa | bbb | ccc | I need a query that will fill the id column with sequential numbers (eg, 1-3 for this example data). I need this to update the table itself, not just a query that shows this in the results. ...

Lucene Query Syntax

Hi, I'm trying to use Lucene to query a domain that has the following structure Student 1-------* Attendance *---------1 Course The data in the domain is summarised below Course.name Attendance.mandatory Student.name ------------------------------------------------- cooking N Bob art Y ...

Is FULL OUTER JOIN really such a bad thing here?

In general, I believe "FULL OUTER JOIN Considered Harmful", to turn the phrase. Background: http://weblogs.sqlteam.com/jeffs/archive/2007/04/19/Full-Outer-Joins.aspx But I do have a specific situation where it would be really handy: Given: CREATE VIEW Calcs(c1, c2, c3, fordate, ...other columns) AS /* Complicated set of equations...

MySql query over many-to-many relationship

A very simple example of a n:m relationship that puzzles me. Let's assume we have two tables "Plant" and "Attribute" and another table between them holding their relationship with their IDs: Plant--------hasAttribute--------Attribute P1 | A1 P1 | A2 P1 | A3 P2 | A1 ...

how to query a folder structure (files, directories)

I need to query folder structure. In other words I need to be able to access directory structure by SQL. I'm thinking of that there should be some OLE DB provider or some ODBC driver for that purpose. My friend said to google "folder monitoring" but I can't find anything Now I'm doing in command prompt dir>somefile and importing resulte...

SQL statement help -- Select customers who ordered today

Say I have a table which stores customers order IDs. Such as | Customer ID | Order ID | Order Date How can I get all customers who have ordered today? Also OrderDate would be a DateTime. Something like SELECT DISTINCT CustomerID FROM TableName Where OrderDate > Today But the last part is what I can't figure out. ...

Update query on linked MySQL table from SQL Server

I have a MS SQL Server with a linked MySQL server. I need to partially synchronize a table between the two servers. This is done in three steps and based on a condition: Delete all rows from the MySQL table that do not satisfy the condition Insert all new rows in the MySQL table that satisfy the condition Update all rows in the MySQL s...

Query input must contain at least one table or query

I'm really hoping that somebody could help me regarding this problem. I am using Microsoft Access 2007 to build some forms while connecting to my sql database. Everything seems ok except the forms inserting data in the database showing this kind of message "Query input must contain at least one table or query" I'm not finding where the...

Natural language statistics query to SQL query converter

We would like to include a facility in an ASP.NET web application that will allow a user to type in a natural language (or reasonably close to natural) question about a SQL data set (SQL Server) and get useful information in return. The sort of results required is to include min, max, std deviation, top 10, total for a column, and anythi...

Please help me debug my SQL query.

I have a query: Select n_portions, dish_name from food_order, dish where n_portions= (select max (n_portions) FROM food_order); It's meant to return: fish pie 3 steak and chips 1 pasta bake 2 stuffed peppers 1 But i get: Pasta bake 35 Fish pie 35 Steak and chips 35 Stuffed peppers 35 Ham and rice 35 Lamb curry ...

Oracle - output not coming in right format

Hi All, I have set the below parameters in sqlplus to display my view out put on unix box,However it is displaying one line gap between two records.I don't want that one line gap between two records Ex- set feedback off SET NEWPAGE NONE set HEADING Off set pagesize 0 set linesize 125 SET TRIMSPOOL ON set termout off spool /export/home/4...