query

Very slow MYSQL query for 2.5 million row table

Hi, I'm really struggling to get a query time down, its currently having to query 2.5 million rows and it takes over 20 seconds here is the query SELECT play_date AS date, COUNT(DISTINCT(email)) AS count FROM log WHERE play_date BETWEEN '2009-02-23' AND '2020-01-01' AND type = 'play' GROUP BY play_date ORDER BY play_date desc; `id` ...

MySQL: Join two tables with different number of rows and one same column name

Hi, i have two tables "*TABLE_A*" and "*TABLE_B*", and i want to connect them the same way like in "*RESULT_TABLE*". TABLE_A: +-----------+-----------+---------+ | row_id | category | val_1 | +-----------+-----------+---------+ | 1067 | cat1 | 6.5 | | 2666 | test | 6.5 | | 2710 | cat1 | 2.1...

MySQL - large query vs Short query with multiple if's

This is a really broad question, but I have come across it a couple of times in the last few weeks and I was wondering what the general consensus is regarding good practice and efficiency. 1) SELECT COUNT(*) FROM table WHERE id='$id', name='$name', owner='$owner_id' and then based on if there is one result then the record matches. 2)...

MySQL Query Browser Multiple Statements

So, I'm using MySQL Query Browser to connect to a remote mysql server and trying to execute multiple statements. But it appears to only execute one statement at a time. For instance, it looks like the query browser is only executing a highlighted line and none of the other statements. Is there any way to execute all the statements in a t...

Querying entities which have a specific collection entry using HQL

I have Item objects which have a collection of attributes defined as a map. Now I want to retrieve all objects which have a specific attribute (by name, locale and value) An expecert of the Item mapping: <map table="ITEM_ATTRIBUTES" name="attributes"> <key column="item_id" foreign-key="fk_itmr_attrbts_itmrs"/> <composite-index clas...

SPSiteDataQuery fails if field of type UserMulti is specified in ViewFields

Hello. I`m trying to query all task lists. I have modified default Task content type to allow multiple choices for Assigned To field (Internal name - AssignedTo). My SPSiteDataQuery fails if I specify <FieldRef Name='AssignedTo' /> (Returns no results) If I add Nullable='TRUE' then results are returned but AssignedTo field ends up bein...

How visible/traceable is local CSV data queried from an ASP.NET page?

I want to have a page on a remote site that selects a local CSV file as a data source which outputs to a GridView. What is the format of the source data and how is it transferred to the server in this instance? Could it be retrieved in some way from a cache or the IIS logs? The data is mildly sensitive and I'd like to know the potenti...

MySQL search multiple tables for information

Hi all!, I'm building a searchfunctionallity where a user can select the different libraries to search in with the provided keywords. Also the AND operator is supported. My problem is that when I try to search for information it gets somehow multiplied or it gets increased exponential?? I'm using a MySQL database and PHP to process the...

SQL query, can i have WHERE as a wildcard?

Hello everybody! Is it possible to have the WHERE as a wildcard in a SQL query? I have this simple query: SQL = "SELECT ID, Firstname, Lastname, Company, City, Email FROM table WHERE * LIKE '%" & q & "%';" lets say the variable q equals "John Doe". Then I want the query to search for q in both Firstname AND/OR (??) Lastname. I just...

Value of column in row with previous key

I'm writing an application which tracks views of various items across time, and I've hit a bit of a snag. I need to get the difference in views between two adjacent updates. The updates are identified by a UNIQUE key, containing the columns time and id. How would I be able to do this, without running multiple queries? SELECT updates.vi...

NHibernate Polymorphic Query on a Collection

I'm trying to write a query in NHibernate. I don't really care if I use the Criteria API or HQL, I just can't figure out how to write the query. Here's my model: public class LogEntry { public DateTime TimeCreated { get; set; } } public class Note : LogEntry { public string Content { get; set; } } public class Workflow { public IList<...

query to check index on a table

i need a query to see if a table already has any indexes on it. ...

Counting all the posts belonging to a category AND its subcategories.

I would really appreciate some help with my problem: I have 2 MySQL tables, categories and posts, laid out (simplified) like so: categories: CATID - name - parent_id posts: PID - name - category What I would like to do is get the total amount of posts for each category, including any posts in subcategories. Right now I am getting...

SQL Query problem

Consider two table.Employee and Project.Employee table has fields like eid,ename.Project table has fields like pid,pname.Now,since an employee can work on many projects and a project can be done by many employees, therefore,as evident,there is a many to many relationship b/w the two tables.Break the many to many,and create a new table ca...

Finding end/start date in MySQL

Look at this MySQL table: +------------+-----------+ | date_key | stude_key | +------------+-----------+ | 2005-09-01 | COM | | 2005-09-02 | COM | | 2005-09-06 | COM | | 2005-09-07 | COM | | 2005-09-08 | COM | | 2005-09-09 | COM | | 2005-09-12 | COM | | 2005-09-01 | YUM | | 2005-...

Combine two small queries (that group by different values) into one query

Please take a look at the following table (called response). It shows what response a respondent has given to a question and answer. questionid answerid respondentid 1 10 1 1 11 2 1 11 4 1 12 3 1 12 5 2 20 1 2 ...

MySQL query to replace spaces in a column with underscores

I have a MySQL database table 'photos' with a column 'filename'. I need to replace the spaces in the filename column values with underscores. Is it possible with a single/multiple query? If so how? ...

Select only first four lines, from Sql text field

Sql Server 2008 Express >> Visual Web Developer >> C# I'm pulling records out of the table like this: SELECT Name, Category, Review FROM ReviewTable This works fine but the Review field Type in SQL Server is text and is very long (think a magazine article). I only want to pull the first four lines from the Review field for each ro...

Case ... When with strings in mysql

Hi I want to have some query like Select case column1 when column2 like '%Test%' then column 3 else 0 end FROM myTable in column2 there are varchars stored. Can someone help me with this? ...

SQL Server: Kill Process using Stored Procedure

Hello all, I want to modify the following as it doesn't seem to kill processes - I think its supposed to disconnect users (is this the same?). I want to be able to kill all process for a particular database - how can I modify the below: create procedure [dbo].[sp_killusers](@database varchar(30)) as ------------------------------------...