sql

Finding all records without associated ones

I have a teams table and a players table and I'm wanting to find all teams that do not have players associated with them. The players table is associated via a team_id column. I'm using Ruby on Rails for this so I have a Team and a Player model. ...

Why some stored procedures do not return data in ASP.Net C#

What I tried to do is generating a text file on ASP.Net using C#. The data is retrived from a database by executing a stored procedure. I ensured that the stored procedures returned values by executing it in SQL server Mangement studio. I was actually able to do just that. I first gether all related tables into a View then using stored ...

PHP/SQL - Hard SELECT question..

I am creating a calendar application. In the Events table, there are two columns, a start and end timestamp. EVENTS - { start_timestamp, end_timestamp } I have two variables in my PHP application. One is the timestamp of the beginning of a month, another is the timestamp of the end of a month. I want to select from the events table ...

What are some good, reasonably-priced SQL Server client tools offering Intellisense for SQL?

SSMS 2008 doesn't have SQL Intellisense when connected to SQL Server 2005! I know of 3 products which enable writing SQL with Intellisense. ApexSQL Edit, Red Gate's SQL Prompt Pro & SQL Assistant. However I am looking for a less expensive solution. Any ideas? ...

How to do this data transformation

This is my input data GroupId Serial Action 1 1 Start 1 2 Run 1 3 Jump 1 8 End 2 9 Shop 2 10 Start 2 11 Run For each activitysequence in a group I want to Find pairs of Actions where Action1.SerialNo = Action2.SerialNo + k and how may times it happens S...

SQL: finding longest date gap

Hello, I have a table with 2 fields: unique ID, user ID (foreign key) and date-time. This is an access-log to a service. I work in SQL Server but I would appreciate agnostic answers. I would like using SQL to find for a certain user the ID from where the longest gap begins. So for example, say my values are as follows (simplification ...

Sql query to find MAx row in subqury

Hi All. These are my tables:User,Product,DiscountGroup,DiscountUser,DiscountProduct. DiscountProduct: id discountGroupId productId discount --- -------------- --------- ------- 1 2 8 2000 2 3 8 1000 3 2 4 4500 Dis...

SQL: what exactly do Primary Keys and Indexes do?

Hi I've recently started developing my first serious application which uses a SQL database, and I'm using phpMyAdmin to set up the tables. There are a couple optional "features" I can give various columns, and I'm not entirely sure what they do: Primary Key Index I know what a PK is for and how to use it, but I guess my question wit...

insert data in multiple tables

hi i have a problem to insert data in multiple tables. i have define primary key & reference key in tables now i want to insert data in both tables in single query.......how can i do this...........??????? ...

Should I make Linux Shell Script or Java program?

I need to generate multiple databases to SQL, so I need script/program to automatically generate those to SQL and generate files to jboss server. Our client server is running in Linux, but I develop on Windows machine. Should I make script with as Linux script or write Java program that could make same things? ...

What is "Linq to SQL"?

I've had a discussion with a colleague about "Linq to SQL". I am still new at .NET so he thinks I need to learn more. (still, 30 years of general programming experience should count in my advantage, right?) I had read some books and for a new project I decided to use the ADO.NET Entity Data Model. My colleague disagreed because he "knew"...

hierarchical category SELECT query in mysql

This is my table: CREATE TABLE IF NOT EXISTS `Category` ( `Name` varchar(25) NOT NULL, `lft` INT UNSIGNED NOT NULL, `rgt` INT UNSIGNED NOT NULL, `CategoryId` int UNSIGNED auto_increment NOT NULL, PRIMARY KEY (`CategoryId`) ) Engine = InnoDb; I have a url that looks like this: products.php?category=5 From the category id I need to re...

sybase - showplan drops estimated I/O greatly by adding another table to query

The application of the query has been changed, but the theory is the same. 4 tables: states - list of states (index on state) stores - stores, and the state they're in (separate indexes on state, store) store_orders - ties an order to a store (separate indexes on store, order) order_statuses - has order and status (separate indexes on ...

What is the purpose of tbl_Product, tbl_Order naming conventions?

I've seen tbl_ prefixes decorating all tables in the last two code bases I've worked with. I can't think of any reason they'd be useful for application developers or database administrators. If a DBA needs to see what objects are tables they can always join up to DMV's or the schema tables in master right? I can't think of how they'd ...

Using 'OR' between HAVING and WHERE clause in MySQL?

I am trying to fetch records in MySQL using a simple used submitted field. More precisely, the user inputs a name (firstname or lastname or fullname) and the server should return matched rows. What I am doing so far is something like: SELECT * FROM people WHERE firstname LIKE '%user_submitted_data%' OR lastname LIKE '%user_sub...

How do I select from multiple mySQL tables and output to PHP?

I have at least 4 tables in MySQL for my PHP application (shortened it for this example) Agents - Agent_ID - Agent_Name Country - Country_ID - Country_Name Job - Job_ID - Job_Type Line_Items - Line_ID - Agent_ID - Country_ID - Job_ID Now, I need to select from Line_Items where Agent_ID = 1, and instead of echo-ing the Agent_ID, Coun...

What data generators?

I'm about to release a FOSS data generator that can generate random yet meaningful data in CSV format. Rather belatedly, I guess, I need to poll the state of the art for such products - because if there is a well known and useful existing tool, I can write my work off to experience. I am aware of of a couple of SQL Server specific tools,...

sql "ranges" and wildcards

Hi. Complete sql noob here. Trying to think about a way to store some data in a table that looks a little like this: "0-15", "low", "1-3" "45-50", "med", "*" "*", "*", "1000" where column 1 & 3 are ranges of integers, and col 2 is an enumerated type (could be stored as whatever really). i want to be able to put in wild...

listing all friends

I have F.FRIENDID, F.MEMBERID columns in FRIENDS table and M.MEMBERID, M.FIRSTNAME, M.LASTNAME in MEMBERS table. I want to list all friends' of signed in member. Issue here is, signed in member's ID can sometimes be in FRIENDID row or MEMBERID row in FRIENDS table. That is because when member adds another member, his or her ID is recorde...

How do I avoid dynamic SQL when using an undetermined number of parameters?

I have a StackOverflow-like tagging system for a database I'm working on. And I'm writing a stored procedure that looks for results based on an undetermined number of tags in a WHERE clause. There could be anywhere between 0 and 10 tags to filter results. So for example the user could be searching for items tagged with 'apple', 'orang...