query

Help with this query

Please can you take a look at this query and point out what I'm doing wrong: update @output set fromdate = o.fromdate, todate = o.todate from ( select fromdate, max(todate) from @output as o left join status as es on o.number = es.empid and o.ccode = es.compcode and @status = es.status ) I'm try...

SQL Server Insert Query help

I have the following code that I use in a Query to update a table called ListClientCasePresentingIncidents which uses a function called fnSplit to split a comma seperated nvarchar named @CasePresentingIncidents. IF ( @CasePresentingIncidents <> '' ) INSERT INTO ListClientCasePresentingIncidents ( PresentingIncident ...

Sending mail or SMS after the query has been executed

Hi, Currently I am dealing with a large dataset and some queries are executing several hours. In the meantime I am doing other things. In order to use time efficiently I have been thinking about implementing the logic to send email or SMS message after the query is complete so I can analyze the data. I know how to do it by writing cust...

querying results from mysql in the last 3 hours?

i want to query blog posts from the database created in the last 3 hours, table blogs{id,blog_text,date} date format: datetime ...

SQL query: list all items in one table that do not appear in another table

I'm working on a training tracker program and I'm at a point where I cant figure out the SQL query. I have 3 tables: employees, trainingRecords, masterList. employees and trainingRecords are related through the empID fkey. trainingRecords and masterList are related through the TID fkey. Right now the training records table is bla...

is it possible to select a specific row index from a mysql select result set?

if I run a SELECT query that returns 10 rows, is there a way to select the 2nd item in the result set right in the SELECT statement (effectively getting a single row result)? psedudo code: SELECT id from MYTABLE where MYTABLE.foo = 0 and RESULT_INDEX = 2; this would return the 2nd item from a multi item result set. ...

SQL query to calculate value from two tables

Hi I have two tables which are related in the following way : Table1 gene goterms ape 1a ape 1b ape 1c boy 2a boy 1a cat 1a cat 1c Table2 gene gene count ape ape 3 ape boy 1 ape cat 2 boy ape 1 boy boy 2 boy cat 1 cat ape 2 cat boy 1 cat cat 2 now,i need value that corresponds to second row ...

How can I select like this using mysql query?

Hi I have two different tables containing lot of images. I need to display 50 random images from both tables. How can I do like that. How can I select random images using MySQL? or if I select 100 images from both tables. How can I choose 50 random images from that array using php? any body knows the solution please help me. ...

Best practice to generate a JPA dynamic, typed query?

Hello there, i'm trying to convert a 'TableController'-Class we used (without ORM) to generate dynamic SQL (actually the order column and direction is appended to the SQL). Think of this 'TableController' as a class that have a function to return a list of Entities of a given class (known at runtime), in a given order (String column/pro...

How to retrieve a cluster of connected users from table of connections between two users?

Hi, The table consists of pairs of users which are connected together. The following is a hypothetical example: user1, user2 a, b a, c c, a c, d d, e a, e j, n g, n f, n By randomly picking up a user from the table (user1 or user2) I would like to retrieve the whole cluster of connections to which the selected user belongs. For examp...

SharePoint CAML query for following condition

Hi All, Can any one tell me what would me the CAML query for the following condition [[Col1=22 And Col2=23] OR [Col3=Yes] ] And [ [Col4=16] OR [Col5=56 ] ] Where Col1,Col2,Col3,Col4,Col5 are the columns of my list and 22,23,Yes 16 And 56 are some mock values. Thanks in advance! Sachin ...

SubQueries - using only one Where statement.

I have the below query, everytime i change it i need to change the stockclientid. I would like it where i only have one where statement to apply to all the sub queries. Is there also a way to apply the same code to return multiple rows? I would like to have the results display for all stockclientIDs rather than just 1. Select (Select...

Query Form Logic: "Like" vs. "Equals"

Our application provides multiple query interfaces that are basically just text inputs. Is there a best practice on whether the backend logic should be pad the query parameter with wildcards then perform a like or should it just do an equals. Of course another option would be to allow user's to use wildcards and then check and use a "l...

how to select particular dataset from sql

Hi, I have a sql query that has two parts 1) Which calls a stored proc and populates the data in the temp table (using openXML function) 2) The other part of sql that joins with this table and the result set Currently when i execute the stored proc it returns me the two result set. But it should return only me the second result set no...

What is the better way to store an arbitrary key:value array in mongodb

I have an array of key values {val1: [{gender:male}, {age:23}, {favorite-color:red}] } The thing about this array is that in no way is it structured and in no way am I ever guaranteed to see the same key value again. For example I could see the following for val2 {val2: [{sex:male}, {hair-color:red}, {height:6'1"}] } My quest...

MS SQL: Use a stored procedures result set in another query?

I have a stored procedure I don't want to modify. It's rather large and complex, and I don't want to add any more confusion to it. So what I would like to do is have another store procedure that calls on the big one, and uses the result set to perform further selects / joins etc. ...

[Doctrine] Query work under Unit tests, not when sent to Doctrine_Pager

I have this relation; Property hasMany Chargerate. Property has column 'default_price'. Chargerate has 'start_date', 'end_date' and 'price' columns. My query is like this: $q = PropertyTable::getInstance()->createQuery('p') ->select('p.*, ROUND(r.price) as cr_price) ->groupBy('p.id') ->leftJoin('p.Chargerate r WITH r.pr...

ordering mysql rows from derived columns?

i wanted to retrieve rows from the mysql database and order them by votes: votes_up + votes_down = votes table: posts{id, post_text, votes_up, votes_down, date} ORDER BY votes ...

incremental SQL query

My application has a fixed set of SQL queries. These queries are run in polling mode, ever 10 seconds. Because of the size of the database (> 100 GB), and the design (uber normalized), I am running into performance issues. Is it possible to get incremental changes to a given query, whenever a CRUD event happens on the DB that changes t...

SQL Query that relies on COUNT from another table? - SQLAlchemy

I need a query that can return the records from table A that have greater than COUNT records in table B. The query needs to be able to go in line with other filters that might be applied on table A. Example case study: I have a person and appointments table. I am looking for all people who have been in for 5 or more appointments. It mu...