sql

mysql multiple queries

Query: SELECT c.Name FROM [Catagories] c SELECT c.Name, bc.CategoryName FROM [Catagories] c INNER JOIN [Business_Categories] bc ON c.BusinessCategoryID = bc.BusinessCategoryID Question: Why don't I have to put this in a WHERE clause? ...

SQL query to fetch products with most top 1 most recent price change.

I'm using SQL Server 2005. Let's say I have a table for products and another table for prices so that I can track price changes over time. I need a query that fetches distinct products (easy part) plus each product's most recent price and the date it changed. Products Table: CREATE TABLE [dbo].[Products]( [ID] [int] IDENTITY(1,1)...

Stored procedure to script database objects to file?

I'd like to write a stored procedure in SQL 2005 to script all my database objects to a file. The only problem is...I have no idea how to do it. Can anyone help? Thanks! ...

SQL Query to retrieve highest item up to a point in a group

The best way of describing this is I have a table of people with their names and ages. Assume that people with the same surname are from the same family. I need a query in oracle which will retrieve a list of the oldest person in each family, but not older than a certain age. Table: person name surname age ==============...

Scalable and performant way to run calculations against a database

A multitennant database for use by telsales agents, a table contains the prospect leads to call. One record is displayed to the agent at a time for him to call, after the call the agent updates the record with a coded call outcome taken from the outcome table. In this table some outcomes have a recycle time, after which the record should...

SQL query against two tables

I have two tables in a MySql DB: items id (char) name (varchar) description (varchar) modified_at (datetime) folders id (int) name (varchar) parent_id (int) From a query against a search index I get back an ordered list of ids for items and folders that matched the query. For example, ("ph76gjd", 34, "rh75ghd", "gr45gfd"). O...

How to keep client side cache in sync ?

I have a SQL server and couple Windows clients and cache of some tables as objects on clients. I currently have a pull mechanism where every one minute or so clients query one row in DB to understand if cache is still good if changed they sync everything, but I want to change this mechanism to push based. I mean I want server to “ping” ...

How do I create a tripcode system?

How would I go about creating a tripcode system (secure) for a message board I'm custom making? I'm only using PHP and SQL. ...

SQL COUNT of COUNT

I have some data I am querying. The table is composed of two columns - a unique ID, and a value. I would like to count the number of times each unique value appears (which can easily be done with a COUNT and GROUP BY), but I then want to be able to count that. So, I would like to see how many items appear twice, three times, etc. So for...

Aggregating schedule data by start and end times

I have a tricky problem that has had me scratching my head for a little while. I have some data that represents the delivery of "widgets" over a variable number of days, broken down into half hourly slots. For example (apologies for formatting - haven't quite got to grips with it): Date Time NoOfUnits 01-Mar-2010 00:00...

Find the most recent shipment for a product (sql subselect?)

I have three tables shipment (shipment_id, shipping_date) company_order (company_order_id, shipment_id, company_id) company_order_item (company_order_item_id, company_order_id, product_id) Several companies get together and aggregate orders from a single manufacturer. This aggregate order is called a "shipment". Companies order a sele...

Relational Database (H2, Java): How do I constrain a foreign key to NOT match another foreign key in the same table?

Simple question. Just wondering if this can be done without me having to enforce this constraint manually in my Java code. These two foreign keys (together in the same table) both refer out to another table, but for each row, they must not be allowed to point to the same foreign item. link text ...

How to have a primary key with null values using empty string ?

I have a table in which I need both the values to be primary because I am referencing this combination as foreign key in the other tables. Table definition and the data I need to put are as follows create table T1 ( sno number(10), desc varchar2(10), constraint T1_PK primary key(sno,desc) ) DATA to put sno | desc -------------...

SQL: Query 2 columns; if one is valid then ignore the other

Hello, I'm not sure how to approach this SQL statement so please advise, even if its just a pointer to something I can read up on I have a table, such as the following ID OVER60 OVER80 1 N N 2 Y N 3 Y Y The IDs are unique, what I need to do is to create a SELECT st...

SQL 2008 Replication - Change Subscriber in push Subscription

I'm running replication on a SQL 2008 server. I have a couple of Push Subscriptions. The IP address for one of my subscribers changed. Eg. (10.10.132.16 to 10.10.132.17) Previously I've used sp_changesubscription to change properties like subscriber_login and subscriber_password on the subscription. However the actual subscriber is n...

Database modeling tool

I am looking for a simple tool to draw up my database in. I know that i saw one that was made in C# on Codeproject but i can't find that one. I just need to be able to visually draw my tables and relations for MS SQLServer 2008. ...

Get latest update from two tables

I have read so many posts and tried so many alternatives but I just can't work out the best way to achieve the following : I have four tables, issues, issuestatus, customers and customerupdates Issues IssueID StatusID CustomerID IssueDetails IssueStatus StatusID Status Customers CustomerID CustomerName CustomerUpdates Update...

SQL- How do you retrieve records matching all values in a linked table.

I have a many to many relationship within my database. For example I have a USER table, a ROLE Table, and USERINROLE table. I have a search on my website that needs to find users in specified roles. For example I would like to retrieve User records who are in roles "reader" AND "writer" My Query before the where looks like this: SELEC...

How do I add months to a CURRENT_TIMESTAMP in SQL?

How can I add months to the CURRENT_TIMESTAMP in SQL Server? The solution probably lies in DATEADD() but this works with a date only, not a datetime. Thanks. ...

c#/.NET SQLite -- REINDEX not working?

Hello all, I'm trying to reindex a table in a simple database that I created using SQLite.NET and VS2008. I need to reindex tables after every DELETE command and here is the code snippet I have written (it does not work): SQLiteCommand currentCommand; String tempString = "REINDEX tf_questions"; //String tempString = "REINDEX [main].tf_...