query

How to find the previous and next record using a single query in MySQL?

Hello, I have a database, and I want to find out the previous and next record ordered by ID, using a single query. I tried to do a union but that does not work. :( SELECT * FROM table WHERE `id` > 1556 LIMIT 1 UNION SELECT * FROM table WHERE `id` <1556 ORDER BY `product_id` LIMIT 1 Any ideas? Thanks a lot. ...

Form input correction & database query- Codeigniter

Hey guys. I'm re-creating a registration for my website using codeigniter. On my previous page I did it in simple php and HTML. Now that I'm trying to recreate it in codeigniter I seem to be running into difficulties. The following code is a function that is called to validate an email address that the user puts in. It is supposed to q...

Deleting a row in MySQL

I have a table: NACHRICHT_ID | VERFASSER_USERNAME | BETREFF | TEXT | DATUM | EMPAENGER_ID ------------------------------------------------------------------------------ | | | | 2009-07-01| 1 | h | hfgh | hfgh | 23:15:10 | 31 --------------------------...

Is there a better way to search over a range of values in Oracle than testing against a subquery?

given this table: x y -- - 10 a 20 b 30 c I want the best way to to map values [10,20) -> a [20,30) -> b [30,inf) -> c Right now I'm using a query like: select y from foo where x=(select max(x) from foo where x<=21); Is there a better way to do this? Is there an analytic function that might help? Here's my te...

New line in Sql Query

How you get new line or line feed in Sql Query ? ...

i want to get records using like keyword

Hi friends!! I have the following query which is working fine, but I also want to get records using the like keyword. My query is as follows, USE [POBox] GO /****** Object: StoredProcedure [dbo].[test] Script Date: 07/06/2009 12:55:39 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[test] --'DateTime'...

Mysql query: retrieve current date query

In mysql database i have this column called: Name: Date Type: datetime I have few values in that column: 2009-01-05 01:23:35 2009-03-08 11:58:11 2009-07-06 10:09:03 How do I retrieve current date? I am using php. in php: <?php $today = date('Y-m-d');?> How to write a mysql query to retrieve all today date data? Should i chang...

Transforming Results of PostgreSQL Query to XML, using PHP DOM

Hey everyone, Given SQL as an input, I have to query a PostgreSQL database and return the results as XML. I have done this with the following code: <?php $link = "host=localhost dbname=company user=pgsql password=password"; $connect = pg_connect($link); $query = "SELECT * FROM customer"; $result = pg_query($connect, $query); $doc =...

SQL help: select the last 3 comments for EACH student?

I have two tables to store student data for a grade-school classroom: Behavior_Log has the columns student_id, comments, date Student_Roster has the columns student_id, firstname, lastname The database is used to store daily comments about student behavior, and sometimes the teacher makes multiple comments about a student in a given da...

How to implement Solr or SolrJ bound query ?

I want to use a query like: sql(select name where id > 10 and id < 100 ) by using Solr or in SolrJ, but do not know how to implement? Can someone explain? ...

ASP Classic Named Paramater in Paramaterized Query: Must declare the scalar variable

Hi all. I'm trying to write a parameterized query in ASP Classic, and it's starting to feel like i'm beating my head against a wall. I'm getting the following error: Must declare the scalar variable "@something". I would swear that is what the hello line does, but maybe i'm missing something... <% OPTION EXPLICIT %> <!-- #includ...

How to optimize oracle query for repeated full table sorts?

I have a database infrastructure where we are regularly (at least once a day) replicating the full content of tables from a source database to approximately 20 target databases. Due to the replication code in use (we have to use regular oracle queries, no control or direct access to source database) - this results in 20 full-table sorts ...

Mysql optimization

I'm currently trying to optimize a MYSQL statement that is taking quite some time. The table this is running on is 600k+ and the query is taking over 10 seconds. SELECT DATE_FORMAT( timestamp, '%Y-%m-%d' ) AS date, COUNT( DISTINCT ( email ) ) AS count FROM log WHERE timestamp > '2009-02-23' AND timestamp < '2020-01-01' AND TYPE = 'play...

LIKE in dynamic queries

I want to use the like keyword in a dynamic parameterized query. I want to protect my query from SQL injections so I don't want to pass the value, instead I want to pass my criteria while executing the query, Is there a way I can do this? SELECT ComposeMail.ID, ComposeMail.DateTime, ComposeMail.Subject, ComposeMail.CreatedB...

SQL Server Table locks in long query - Solution: NoLock?

a report in my application runs a query that needs between 5 - 15 seconds (constrained to count of rows that will be returned). The query has 8 joins to nearly all main-tables of my application (Customers, sales, units etc). A little tool shows me, that in this time, all those 8 tables are locked with a shared table lock. That means, no...

SQL Express 2008 - what's a reasonable aplication size for it's 'limitations'?

Without wanting to sound too stupid, SQL Express is free and the free resources make it a good choice for a beginner like me. I know it has limitations (read other posts) but the figures mean little to me I'm afraid. Can anyone give me ball park figures on the number of users it can handle? I'm looking at possibly 40-50 users maximum,...

LINQ - Select correct values from nested collection

Consider the following class hierarchy: public class Foo { public string Name { get; set; } public int Value { get; set; } } public class Bar { public string Name { get; set; } public IEnumerable<Foo> TheFoo { get; set; } } public class Host { public void Go() { IEnumerable<Bar> allBar = //Build up some large list //Get...

Anyone care to help optimize a MySQL query?

Here's the query: SELECT COUNT(*) AS c, MAX(`followers_count`) AS max_fc, MIN(`followers_count`) AS min_fc, MAX(`following_count`) AS max_fgc, MIN(`following_count`) AS min_fgc, SUM(`followers_count`) AS fc, SUM(`following_count`) AS fgc, MAX(`updates_count`) AS max_uc, MIN(`updates_count`) AS min_uc, SUM(`u...

How to run query, automate using VBA Macro and Excel, make "loading" feature while reconciling?

Hi, I am building a reconciliation tool via VBA that automates queries from my oracle database and a worksheet. When I run the query I want the user to input what ITEM (in this case pipeline) to query (the worksheet has many items) and the end/start dates. I am having trouble figuring out the following: 1) It is querying - if the value ...

How can I optmize a MAX date query relating to a other table entity

I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because the id field of the table containing the maxDate needs to relate to the other table. The working query is: SELECT maxReadDate, Equip.idProtocol FROM Equip, ( SELECT idEquip as idEquipTot, MAX(readDate) AS maxReadDate ...