query

Complex SQL query, one to many relationship

Hey SO, I have a query such that I need to get A specific dog All comments relating to that dog The user who posted each comment All links to images of the dog the user who posted each link I've tried a several things, and can't figure out quite how to work it. Here's what I have (condensed so you don't have to wade through it all...

How do I write this GROUP BY query in MYSQL?

Suppose I have a column called "fruits" I want to select all of the top fruits, ranked by fruits (and group by + count). Fruits: orange orange apple banana apple apple In this case, the select statement would return: apple, 3 orange, 2 banana, 1 ...

ActionScript - clicking and determining the sprite's class

i'd like to add all or most of my mouse events to stage, but in order to do that i need to be able to tell what is the type of the sprite being clicked. i've added two sprites to the display list, one of which is from a class called Square, the other from a class called Circle. var mySquare:Sprite = new Square(); var myCircle:Sprite = ...

getting mysql_insert_id() while using ON DUPLICATE KEY UPDATE with PHP

Hi-- I've found a few answers for this using mySQL alone, but I was hoping someone could show me a way to get the ID of the last inserted or updated row of a mysql DB when using PHP to handle the inserts/updates. Currently I have something like this, where column3 is a unique key, and there's also an id column that's an autoincremented ...

ROW_NUMBER() VS. DISTINCT

Dear All, I have a problem with ROW_NUMBER() , if i used it with DISTINCT in the following Query I have 2 scenarios: 1- run this query direct : give me for example 400 record as a result 2- uncomment a line which start with [--Uncomment1--] : give me 700 record as a result it duplicated some records not all the records what I want is...

c# linq to xml dynamic query

Right, bit of a strange question; I have been doing some linq to XML work recently (see my other recent posts here and here). Basically, I want to be able to create a query that checks whether a textbox is null before it's value is included in the query, like so: XDocument db = XDocument.Load(xmlPath); var query = (from vals in db.Desc...

SQL ENQUIRY In how to Get defined number of records

I have a select statement, retrieve about 1000 record I want to modify it to return only some records defined by @startIndex and @count e.g. : If I said @startIndex=20 and @count=20 the result will be : from the 21th record to 40th I try to make it, but it take the same time as if I retrieve the 1000 record what is the best way to do ...

solr JOIN query

I need to run a JOIN query on a solr index. I've got two xmls that I have indexed, person.xml and subject.xml. Person: <doc> <field name="id">P39126</field> <field name="family">Smith</field> <field name="given">John</field> <field name="subject">S1276</field> <field name="subject">S1312</field> </doc> Subject: <doc> <field name="id...

Date and time Query - problem

hi, I try to run this query: select * from WorkTbl where ((Tdate >= '20100414' AND Ttime >= '06:00') and (Tdate <= '20100415' AND Ttime <= '06:00')) I have this date: 14/04/2010 and time: 14:00 I cant see hem, how to fix the query? Thank's in advance ...

php mysql query strings array

i am building a string that i check in mysql db. eg: formFields[] is an array - input1 is: string1 array_push(strings, formFields) 1st string and mysql query looks like this: "select * from my table where id in (strings)" formFields[] is an array - input2 is: string1, string2 array_push(strings, formFields) 2nd string and mysql query l...

SQL Table Setup Advice

Hi all. Basically I have an xml feed from an offsite server. The xml feed has one parameter ?value=n now N can only be between 1 and 30 What ever value i pick, there will always be 4000 rows returned from the XML file. My script will call this xml file 30 times for each value once a day. So thats 120000 rows. I will be doing quite comp...

running same query in different databases

I wrote a query that I want to run in several access databases. I have 1000+ access databases with the same tables (same names, same fields). So far, I have been manually copying this query from a txt file to the sql view in the access query design screen for each database and then run it. I did not need to change the query language - ev...

Display rows from MySQL where a datetime is within the next hour

I always have trouble with complicated SQL queries. This is what I have $query = ' SELECT id, name, info, date_time FROM acms_events WHERE date_time = DATE_SUB(NOW(), INTERVAL 1 HOUR) AND active = 1 ORDER B...

MySQL Query WHERE Including CASE or IF?

Strange problem. My Query looks like SELECT DISTINCT ID, `etcetc`, `if/elses over muliple joined tables` FROM table1 AS `t1` # some joins, eventually unrelated in that context WHERE # some standard where statements, they work/ CASE WHEN `t1`.`field` = "foo" THEN (`t1`.`anOtherField` != 123 AND `t1`.`anOtherField` != 456 A...

Zend Framework how to echo value of SUM query

Hello, I created a query for the zend framework, in which I try to retrieve the sum of a column, in this case the column named 'time'. This is the query I use: $this->timequery = $this->db_tasks->fetchAll($this->db_tasks->select()->from('tasks', 'SUM(time)')->where('projectnumber =' . $this->value_project)); $this->view->sumtime = $t...

SQL: column <> '%TEST%' does not work, why?

Hi, I do not understand why following code does not work? SELECT [column1], [column2] FROM table where Column1 <> ('%TEST%') ORDER BY 1 I want to have all rows where Column1 does not contain TEST Thanks ...

Help me with Linq query please

I'm trying to get all the assets where Class property equals to one of the values in selectedIClassesList; Something like this: from x in Assets where selectedIClassesList.Contains(x.Class) select x ...

Where clause on joined table used for user defined key/value pairs

Our application allows administrators to add “User Properties” in order for them to be able to tailor the system to match their own HR systems. For example, if your company has departments, you can define “Departments” in the Properties table and then add values that correspond to “Departments” such as “Jewelry”, “Electronics” etc… You...

SQL: Limit rows linked to each joined row

Hello, I've certain situation that requires certain result set from MySQL query, let's see the current query first & then ask my question: SELECT thread.dateline AS tdateline, post.dateline AS pdateline, MIN(post.dateline) FROM thread AS thread LEFT JOIN post AS post ON(thread.threadid = post.threadid) LEFT JOI...

SQL Command for the following table.

I have a table named with "Sales" having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i want to generate a sales summary to view the total sales by zone and then by district and then by State by which distributor for the last/past month period. How can i write a Sql Statement to do this...