sql

How can I match "laptop" and "laptops" when search for "laptop" is performed using MySQL's match...against full-text search?

I'm trying to build a search feature in to my website. Searching is the primary purpose of the site and I am having a few issues with the MySQL search feature. I would like to be able to search with a single search string against multiple text fields. I'm using MySQL's match...against statements to perform a full-text search. I'm runni...

setting the result of a sql query as a variable inside an if statement in php

Kind of an unclear question but I'm trying to check if a username has been taken or not. The code I have now isn't erroring but it's also not working, when echoing the $username variable I get nothing. $sql="SELECT people_username FROM people WHERE people_username='{$_POST['username']}'"; //Set the result of the query as $username...

postgresql challenge: how to select sum of one column having another column like 'ab%'

fips value scc param 1 1 123 CO 1 1.1 124 CO 1 1.2 125 notCO 2 1.3 122 CO 2 1.4 142 CO I would like to select the sum of value where scc starts with "12" and param="CO" and have them grouped by fips. SCC is unique per fips (as in multiple fips might have same s...

What is the Correct Way To Have An Adjustments View Between Two Tables in SQL

I'm looking for a way to non-destructively alter data. I have one table that has data that shouldn't be edited - it is the master data. I would like to have user edits on this data, but in order to maintain the integrity of the master data I've created a second table that is a mirror of the structure of the master table. My thinking i...

How to get unique set of rows from SQL where uniqueness is defined by 2 columns?

If I have a table as follows: ID | Name | Category | Parent | URL | LastModified If two rows have the same Name and parent, then they are not unique. How do I get the unique set of rows in this case (but return more than the columns that make them unique)? So, for more details: This is a corporate keywords table, where keywords are o...

View vs ODBC query

I am designing a database in PostgreSQL on a dedicated server. I want certain complex queries to be run often, and the results to be accessible with ODBC/JDBC clients such as MS-Access or reporting software. As I see it, I have the option to either define a VIEW within PostgreSQL and import it using ODBC, or to define the query within t...

Optimising a haversine formula SQL call in PHP

I'm creating an MySQL call using PHP, I'm calculating distance using the haversine forumula: SELECT name, id, (6371 * acos(cos(radians(' . $lat . ')) * cos(radians(geoname.latitude)) * cos(radians(geoname.longitude) - radians(' . $lon . ')) + sin(radians(' . $lat . ')) * sin(radians(geoname.latitude)))) AS distance ...

SQL FOR XML Help

Prob an easy question, but I am new to forming XML in SQL 2005, but What would be the best FOR XML SQL statement to use to form the XML seen below from a table that looks like this? Column1 Column2 ------------------------ Baseball Football Cricket Polo Swim Beach Desired XML output: <Category Nam...

SELECT query slow when flag column is a constraint

I have a fairly simple table called widgets. Each row holds an id, a description, and an is_visible flag: CREATE TABLE `widgets` ( `id` int auto_increment primary key, `description` varchar(255), `is_visible` tinyint(1) default 1 ); I'd like to issue a query that selects the descriptions of a subset of visible widgets. The f...

What strategies are available for migrating Access databases to SQL server-based applications?

I'm considering undertaking a project to migrate a very large MS Access application to a new system based on SQL Server. The existing system is essentially an ERP application with a couple of dozen users, all sharing the Access database over the network. The database has around 300 tables and lots of messy VBA code. This system is beginn...

Javascript Database Mass Insert

I am trying to insert over 70,000 rows into a javascript database (using Chrome 5.0.317.2). The inserts are taking a very long time. The actual page loads in a few seconds, and I can see progress as the percent increases very slowly as each row is inserted. It took about an hour to finish inserting all the records. Is there a way to opti...

Ordering by the difference between two averages

I have a single table called orders. It has 3 fields I care about: price, type, and bid. Bid is an int with either 0 or 1 depending on if the order is to buy or sell something. 1 is buy, 0 is sell. orders |typeID |price |bid| |1 |10 |0| |2 |20 |0| |3 |30 |0| |4 |50 |0| |1 |80 |0| |2 |...

SQL query alignment change when Arabic characters are inserted

I have a query like this SET QUOTED_IDENTIFIER OFF SET DATEFORMAT 'mdy' INSERT INTO TABLE1 (AccountID, TimeStamp, UserID, NodeID, Deleted, UserPriority, ParentRecordID, NodeLevel, Name, NodeClass, DeviceID, DeviceType, SubTypeLevel) VALUES (0, "10/03/2002 02:33:39", 0, 0, 0, 0, 0, 0,"XXXXXX",7000, 0, 0, 0`) When I replace ...

MySql cache problems... some questions

First of all, I am using PhpMyAdmin, is this okay or not? Because when I have cache disabled, and do two queries after eachother, the second query always is faster, so I am thinking maybe there is an internal cache on PhpMyAdmin? Secondly, is there any way to get the time of how long a query takes, into php, and echo it onto the browser...

query_cache_min_res_unit; What is it and what does it do?

I am setting up cache in MySQL. Could someone please explain query_cache_min_res_unit? What does it do etc? I have read the manual and it doesn't explain so good. Details are appreciated... Or examples... Thanks ...

Is there a way to run a stored procedure at predefined intervals?

Hi I wanted a stored procedure to run at specified intervals everyday. Is there a way to do the same on SQL Server 2005? I know we can create a batch file to run SP and schedule it with windows scheduled tasks but is there a way to do it from SQL Server itself? ...

How to avoid IndexOutOfRangeException indexing DataReader columns?

I am having a little trouble with an 'IndexOutOfRangeException'. I think it is because when the code tries to get the DateModified col from the database it sometimes contains NULLS (the users haven't always updated the page since they created it). Here is my code; s = ("select datemodified, maintainedby, email, hitcount from updates wh...

SQL query to show most ordered product

I have this table structure Product product_id (PK) name Order_Detail order_detail_id product_id quantity Example data Product : 1 product1 2 product2 3 product3 4 product4 5 product5 Order_Detail : 1 3 2 2 3 1 3 3 1 4 2 1 5 2 1 6 1 1 7 4 1 8 5 1 9 1 1 10 2 1 11 3 1 Please help me to get top 3 ordered product based on how m...

Get top one record of same FK on date difference.

I need to get top 1 record from same customer inserted within one hour. If record is inserted after one hour then don't need that one. Please see following table. This is just a sample of 1000s of records. I am using SQL Server 2005. ...

Defined patern for mysql table primary key

Hi, is there anyway to create lets say pattern for primary key i.e. for table products such pattern would by p-1,p-2... p-n etc. Thanks ...