query

What is a SQL statement to select an item that has several attributes in an item/attribute list?

Say I have a table that has items and attributes listed like, frog green cat furry frog nice cat 4 legs frog 4 legs From the items column I want to select unique objects that have both the green and 4 legs attribute. I would expect to get back just the frog object in this case. What is the most efficient query to do t...

Iterate over all Query Values in C#

I'm trying to iterate over an unknown number of query values in C#... and can't find anything unrelated to LINQ, which I can't use. Anyone have any ideas? ...

SQL: Select the highest conditional sum on a table

I have an OrdersProducts tables with order_id, product_id, and quantity fields. I'd like to know the most popular products, so how can I sum the quantity field for each product_id separately and then order the sums? Any pointers would be appreciated. I'm using MySQL 5.3, thanks. ...

Rails find query with no duplicates

How do I change the following bit of code so that I only have records with distinct sender_id and message_id combinations: @roles = Role.find_all_by_simulation_id(session[:sim_id]) @messages = RolesMessages.find(:all, :conditions => ["sender_id IN (?) ", @roles.map(&:id)], :order => 'created_at DESC') ...

SQL: Insert multiple sets of values in one statement?

Is it possible to insert multiple sets of values to a SQLite table in one statement? I was trying: INSERT INTO the_table VALUES (1,2,'hi'),(2,0,'foo'); with the different ()s representing different insert sets, but I get an error. ...

mysqli array -> query not attaining correct data

Hello, my mysqli_fetch_array(mysqi_query($db, $query)) doesn't appear to be getting the correct information from the database, and therefore, the PHP application is not working as it should. Here are the queries, <?php if($_GET){ $current = mysqli_fetch_array(mysqli_query($db, "SELECT * from `tbl_user` WHERE `userid` = '".$_GET['useri...

Group and count in Rails

I have this bit of code and I get an empty object. @results = PollRoles.find( :all, :select => 'option_id, count(*) count', :group => 'option_id', :conditions => ["poll_id = ?", @poll.id]) Is this the correct way of writing the query? I want a collection of records that have an option id and the number of...

Query html tag with XPath

I am writing the selenium test. I have a label there "Assign Designer" and the select box followed right after the label. Unfortunetely, select box has the dynamic id and I can not query it by id or any other it's attribute. Can I build the XPath query that returns "First select tag after text 'Assign Designer'"? PS. Selenium supports...

Is there a way to TRUNCATE most tables in a MySQL schema?

I'm looking for a query (or series of) to TRUNCATE all tables in my schema (which has a few hundred tables) EXCEPT for a 4 specific ones. How might I go about doing that? Thanks! ...

How to use LINQ to retrieve child collection

Starting here: public class Customer { public int CustomerID { get; set; } public string CustomerName { get; set; } public IList<Order> Orders { get; set; } } public class Order { public int OrderID { get; set; } public int CustomerID { get; set; } } What would be the linq query that you write to retrieve all Orders from ...

How to make comment reply query in MYSQL?

I am having comment reply (only till one level) functionality. All comments can have as many as replies but no replies can have their further replies. So my database table structure is like below Id ParentId Comment 1 0 this is come sample comment text 2 0 this is come sample comment text 3 0 ...

What is the best online SQL tutorial for learning to write complex reporting queries?

My SQL skills are rather limited and since I find myself working with a DB (Oracle) a lot lately I would like to get beyond the basic select statements. I want to write queries that do things like get data from multiple tables, sum quantities, compare dates, group, filter etc. What sites can you recommend for getting SQL reporting skil...

using results from one mysql for a second query

I have two tables: posts - holds post information listen - holds information on what other users you are listening to. (what users posts you want to view) The structure of listen is: id(uniqueid) userid(the users unique id) listenid(id of a user they are listening too) How would I gather all the entries from listen that mach...

JPA NamedQuery does not pick up changes to modified Entity

I have a method that retrieves Entities using a NamedQuery. I update a value of each entity and then run another named query (in the same method and Transaction) filtering by the old value and it returns the same Entities as if I had not changed them. I understand that the EntityManager needs to be flushed and also that it should happen...

Mysql count columns of users, and group by modified date

There are 2 columns that I want data from. Basically I want to see new signups per day. Go easy on me, my first day with mysql (or any DB for that matter) So far I have this mysql> select created, count(id) from user group by created; +---------------------+-----------+ | created | count(id) | +---------------------+-------...

Access 2003/2007 Query contents wiped

Has anyone else come across a situation where the contents (SQL statement) of an Access 2003 or 2007 was completely wiped (the Query object still exists, the inner SQL does not)? Does anyone know what causes this? I've just had this happen to me again. 2 queries run from a Macro's OutputTo actions to generate 2 Excel files. I ran the ...

Fastest way to query for object existence in NHibernate

Hello, I am looking for the fastest way to check for the existence of an object. The scenario is pretty simple, assume a directory tool, which reads the current hard drive. When a directory is found, it should be either created, or, if already present, updated. First lets only focus on the creation part: public static DatabaseDire...

Complicated Access SQL Query exclusion

For an access database that looks like this: (All text fields) Co1 Co2 Co3 Co4 A k t N1 B k t N2 A m t N3 B k z N4 A k z N5 C m t N6 C k z N7 C k t N8 A k t N9 C m t N10 I need to create some kind of reports that would do the following: The results needs to select rows: Ordered by Co1 first then ordered by Co2 ...

Query a recordset from an existing query Linq To Sql

I'm in a little bit of a road block here, but what I would like to ultimately do is to create a recordset based off of a query and store the information into separate objects (let's call them Foo) then create a new query to group all the Foo objects with the same id's into an ArrayList into Bar objects. How would I go about doing this in...

Combine Multiple Fields into One Text Field in SQL Server

So I have a table that looks like this: Name ID TaskID HoursAssigned ---------------------------------------------------------------- John Smith 4592 A01 40 Matthew Jones 2863 A01 20 Jake Adams 1182 A01 100 Matth...