query

SQL code needed for Query

Hi all, I need SQL code for a query I need to do in Access. I have a table with multiple fields but I only need 2 fields for the query. 1 is a date field. let's call that one DateField. the other is a field that contains text, let's call lit TextField. I need a query that returns the following: The COUNT of DateField (i.e. how many th...

SQLException in JDBC

Hi, I am getting a SQLException when I try to run the query in Informix DB using JDBC. The query is huge in size: select * table_name where tableid in (....) I get an exception because the 'in' part contain more than 5000 values and because of the length. Is there a way to avoid this or should I break it down and run two queries? ...

Noob need help in age calculation

This query method works : SELECT xxx FROM xxx-table WHERE YEAR( CURRENT_DATE( ) ) - YEAR( '1988-10-27' ) - ( DATE_FORMAT( CURRENT_DATE( ) , '%m-%y' ) < '12-31' ) Between 20 and 25 But what I need is something like this... SELECT YEAR( CURRENT_DATE( ) ) ...

How to compare rows with out returning it in a query

I am trying to count the no of buses based on no of conditions. Problem is in a subquery it is returning 2 rows. I am expecting the count to be = 1 if all conditions are true. but it is giving it according to returned rows. Can u plz help how can i just compare rows instead of returning rows. ...

SPARQL xsd:dateTime equality

I have a SPARQL query: PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt; PREFIX person: <http://www.myOntDomain/person#&gt; PREFIX likedEvent: <http://www.myOntDomain/likedEventRule#&gt; PREFIX event: <http://www.myOntDomain/event#&gt; PREFIX owl: <http://www.w3.org/2002/07/owl#&gt; PREFIX xsd: <http://www.w3.org/2001/XMLS...

Edit query in MS-Access with a subquery containg a SUM() field

When I open this query in Access (which is just a collection of 2 linked tables) I'm able to edit the data with no problems whatsoever. SELECT O.*, PP.skuapexid FROM tblSkuBestellingen AS O INNER JOIN tblSkuApex AS PP ON (PP.begindatum <= O.besteldatum) AND (PP.sku = O.sku) WHERE NOT EXISTS ( SELECT * FROM tblSkuApex PP2 ...

Using Regex in SQL Server, I couldn't solve the following problem.

Hello all, I have strings like that OPEN SYSTEMS SUB GR (GM/BTIB(1111)/BTITDBL(2222)/BTVY(4444)/ACSVTYSAG) and I need to extract 2222 from it. What I was doing is this on the GROUPS String: SUBSTRING(GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS,0)+1)+1)+1, 4 ) AS GroupNo However I see that it is no...

Reducing the recordset where a particular field has similar data. (MySQL)

I have two tables, 'discussion' and 'discussion_responses'. A unique ID from 'discussion' is used in 'discussion_responses' to identify the response to the original post in a forum. I created the following query to extract the posts that have NEW replies, but are NOT linked to new topics. Both tables have a field for the date added and '...

django - 3-model set all, with joining?

I have these models: class A(Model): pass class B(Model): the_a = ForeignKey(A) class C(Model): the_b = ForeignKey(B) somewhere in code, I have an A instance. I know how to get all of the B's associated with A; A.b_set.all() - but is there a way to get all of the C's associated with all the B's associated with my A, without...

MySQL Query - Result Table Name

When I query a mysql database in PHP, I can not figure out how to specify the table of the field in the result set. For example, I would like to do the following: $row = mysql_fetch_assoc($result); $row["table.FIELD"]; But, can not figure out how. Surely, it is able to happen somehow. EDIT: I have checked documentation, and have f...

Print rows that dont exist in table???

Simple question. I have a query that sums rows grouped by date. Basically, it counts how many membership applications in a day and prints out the results day by day. Naturally, if there are no applications in a day, it doesnt show that row (example below 15th and 17th had no applications..... Date | Applications ------------...

TIBQuery.Unidirectional = True. How can I rewrite code ?

I have many methods in legacy code that use a TIBQuery (Interbase) with Unidirectional property = False. The problem is that users sometimes get out of memory exception. I suspect it could be fixed by setting this property to True as there is no need to cache the records. Of course I don't want to broke the old code but I also want to f...

SQL : find rows and sort according to number of matching columns?

Let's imagine that we are having "cars" table with such a simple structure... car_id INT color ENUM('black','white','blue') weight ENUM('light','medium','heavy') type ENUM('van','sedan','limo') Fist, I'm selecting car (1, black, heavy, limo), then I'd like to get list of related cars sorted by number of matching columns (without any c...

What is the best natural query language for SQL?

Hi Guys, I am looking for simple query language for producing SQL commands... For example: Google Base Query Language (code.google.com/apis/base/docs/2.0/query-lang-spec.html) CQL (Common Query Language) Lucene Query Language (lucene.apache.org/java/2_3_2/queryparsersyntax.html) Anybody could help me please? Thanks ...

Sql Splitting Function

I have a string like that "10*cat*123456;12*rat*789;15*horse*365" i want to split it to be like that "cat, rat, horse" I have made this Function CREATE FUNCTION [dbo].[Split](@BenNames VARCHAR(2000)) RETURNS VARCHAR(2000) AS BEGIN DECLARE @tmp VARCHAR(2000) SET @tmp = @BenNames SET @tmp = SUBSTRING( S...

Java - Hibernate - Query - Association

Hi everybody, I have three classes -> Metadata, MetadataValue and MetadataMetadataValue: Metadata private long id; private Metadata parent; private long levelInTree; private String code; private String nameEn; private String nameFr; private String descriptionEn; private String descriptionFr; private String query; private String metada...

Finding all rows in a database where a field is different from another field

I have the following SQL query: SELECT * FROM table WHERE field_1 <> field_2 Which is the best index structure to use, to keep this query efficient: two indexes on field_1 and field_2 or a single index which includes both fields? EDIT: The database is MySQL ...

SQL Server Query Execution flow

I am looking for information about how SQL Server actually handles query execution in finer details (like what data is kept in buffer/memory and how does it decide to get fresh data even if there is an update change in only one column of a table involved in a query etc) If anyone knows sources please let me know? We have an web appli...

SQL Server: Select in vs or?

Which is faster? SELECT UserName FROM dbo.UserTable WHERE UserID in (1,3,4) SELECT UserName FROM dbo.UserTable WHERE UserID = 1 OR UserID = 3 OR UserID = 4 ...

Simple AJAX query in chrome/safari providing not-so-simple debugging situation.

Hi, I have a very simple jQuery/ajax script for a membership driven website. The script just checks to see if the user entered info, validates it against my database and returns 1 for a failed login attempt, and 0 if the username/password match. The function works perfectly when I run it w/o calling it from ajax. Firefox: everythin...