sql

performance issue on displaying records

I have a table with just 3,000 records. I render these 3000 records in the home page without pagination, my client is not interested in pagination... So to show page completely it takes around 1 min, 15 sec. What can be done to make the page load more quickly? My table structure: customer table customer id customer name guider id ...

SQL::Self join a table to satisfy a particular condition?

I have the following table: mysql> SELECT * FROM temp; +----+------+ | id | a | +----+------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | | 4 | 4 | +----+------+ I am trying to get the following output: +----+------+------+ | id | a | a | +----+------+------+ | 1 | 1 | 2 | | 2 | 2 | 3 | | 3 | 3 | ...

Find SQL rows that are not shared between two tables with identical fields

I have two tables with identical fields that share many rows. I'd like to list all the rows in one table that cannot be matched in the other. Specifically, these two tables are two different versions of an experiment where the results differ slightly. An example is something like this: |TableA| -------- horse cat cow table |TableB| ...

Best way to store and retrieve comment replies in sql server

Hi, I want to store comment replies in database table. I have a table to store comments: comment_id comment_par_id, comment_from comment_text comment date .... New comment has par_id=0 while the replies has par_id set to comment id to which it was replied. The nesting is just one level. Reply to a reply also has the same parent id. ...

In MySQL, does putting SELECT foo increase in performance if foo is indexed?

In MySQL, does putting SELECT foo increase in performance if foo is indexed? At RedditMirror.cc, I have a database with 1.2 million records in the GrabbedSites table, a number that increases by approx 500-2000 per day. Early in my career, I was mentored that the only columns that should be indexed are those which you will do WHERE o...

counting data and grouping by week in mysql

this is my DB table: CREATE TABLE IF NOT EXISTS `inspection_report` ( `Inspection_datetime` datetime NOT NULL, `Line` char(5) NOT NULL, `S` int(11) NOT NULL, `A` int(11) NOT NULL, `B` int(11) NOT NULL, `C` int(11) NOT NULL, INSERT INTO `inspection_report` (`Inspection_datetime`,`Line`,`S`, `A`, `B`, `C`) VALU...

simple sql for mass changing passwords

Changing password for user 1 looks like this: UPDATE `mydb`.`wp_users` SET `user_pass` = MD5( 'password' ) WHERE `wp_users`.`ID` = 1; Now, I have text file with such format: user30 pass30 ... user2 pass2 user1 pass1 How can I change passwords for all these users without doing it manually? Maybe some sql command that could imp...

Using SQL Server as a DB queue with multiple clients

Given a table that is acting as a queue, how can I best configure the table/queries so that multiple clients process from the queue concurrently? For example, the table below indicates a command that a worker must process. When the worker is done, it will set the processed value to true. | ID | COMMAND | PROCESSED | | 1 | ... | tr...

Optimize Oracle SQL with large 'IN' clause

Here I have a query like below: SELECT field FROM table WHERE value IN ('val1', 'val2', 'val3', ... 'valn') Let's say there are 2000 values inside the IN clause, the value doesn't exist in other table. Do you have any idea to speed up this operation? The question is open to accept any kind of methods.. Thanks! ...

Upgrade from SQL 2005 EXPRESS to SQL 2008 EXPRESS

Hello friends, I restored My database in SQL 2005 of size more than 4 GB but it creates problem when i save picture (image data) in database.i.e i can't save it.So i searched for that problem and came to know that SQL Express 2005 has database size limit of 4 GB. i upgraded it to SQL EXPRESS 2008 and restored it to there.Still it has t...

Full Text-Search and Email notifications

Hi guys, I am going to implement search capabilities and Email messaging to my website. Any tips and tricks / Guidenance that I can use to implement these features ? I am using .NET. Thanks. ...

How to create BIRT report based on multiple data sets

I need help in creating a BIRT report; the situation is that I have multiple queries but the report all columns should be grouped by One column for example (Operator) Like : Operator | Expr1 | Expr2 | Expr3 | Expr4 | op1 | ## | ## | ## | ## | op2 | ## | ## | ## | ## | op3 | ## | ## | ## ...

SQLite SELECT that returns ids and positions

Using a SQLite SELECT statement, I'd like to be able to get the position of each results. Is that even possible? Table: fk_id idx 0 0 0 1 0 2 1 0 1 1 1 3 1 4 2 0 Having [fk_id, idx] being unique. Query: SELECT `idx`, <??> from `mytable` WHERE `fk_id`=1 Results: idx <??> 0 ...

Need help with a query

Hi have a 2 tables organized in this way: table_users |user_id|username| table_products |product_id|user_id| Now, I have some orphan entries in 'table_products'. With this query I check how many products I have: SELECT count(product_id) FROM table_products This query show me the number of the products associated to the users: SE...

Need Help optimizing a complex MySQL query

I have this query below. There are 4 main tables involved: tblOrder, tblItems, tblOrder_archive, tblItem_archive. Orders and Items get moved over to the archived versions of the tables after a few months as not to slow down the main table queries. (sales and traffic is REALLY HIGH). So to get sales figures, i select what i need from each...

grant select for temporary table in MySQL

I have a MySQL DB with a user that has access only a few tables. This user has been granted CREATE TEMPORARY TABLES for this database and by watching the query logs, I can see them create a temporary table and then fail while trying to select from it. Doing GRANT SELECT ON TABLE 'db'.'tmp_tbl' TO 'user'@'localhost'; doesn't work as the t...

How do you repeat a raw SQL query # times to MySQL?

I want to test the load a MySQL server can handle using a couple versions of a query and for that I'm looking for something like apachebench (but for mysql). I'm hoping to run 500 or more concurrent requests every second for a couple minutes and see if MySQL is up to the challenge. ...

Postgres: Find position of a specific row within a resultset?

Hello, I'm trying to figure out how to get the relative position of a single item in a query relative to all the items returned from the query. For example,the long hand way of getting the answer would be: single_item = SELECT * FROM table WHERE id=65 result = SELECT * FROM table WHERE published_date < date_value x=1 foreach(result as...

SQL Server 2008: Bulk Datatype Change

I have an SQL Server 2008 database with many tables. I've been using the now lame datetime datatype and want to use the new and better datetime2. In most places where I have a datetime field, the corresponding column name is Timestamp. Is there anywhere to do a bulk change from datatime to datetime2? ...

pull averages and counts based on a set of calculated time ranges mysql

I have 2 tables - sentiment & comments - that I'm trying to join averages and counts from based on a set of derived time ranges in mysql. Here's what I have that works individually: SELECT ROUND(AVG(sentiment.sent_value)) AS sentiment, ROUND( FLOOR( (sentiment.sent_video_time) /5000 ) *5000 ) AS start_time, ' - ', ...