sql

Help with SQL query (Joining views?)

I have a table with columns Index, Date where an Index may have multiple Dates, and my goal is the following: select a list that looks like Index, MinDate, MaxDate where each Index is listed only once, and MinDate (MaxDate) represents the earliest (latest) date present in the entire table for that index. That's easy enough, ...

Database table for grades

I'm trying to define a table to store student grades for a online report card. I can't decide how to do it, though. The grades are given by subject, in a trimestral period. Every trimester has a average grade, the total missed classes and a "recovering grade" (i don't know the right term in english, but it's an extra test you take to tr...

Is there a clean way of cleaning up duplicate entries in MySQL?

In a table, I have three columns - id, name, and count. A good number of name columns are identical (due to the lack of a UNIQUE early on) and I want to fix this. However, the id column is used by other (4 or 5, I think - I would have to check the docs) tables to look up the name and just removing them would break things. So is there a g...

Storing video duration time in sql server.

What's the most appropriate type used to store the duration time information of a video in sql server? ...

Schema, Owner for objects in MS SQL

By default, objects (tables, stored procedures, etc) are set up with the dbo owner/schema (I think ms sql 2000 calls it owner, while ms sql 2005 calls it schema) The owner/schema is really a role or user in the database. I've always left the default of dbo, but I've recently seen some examples in microsoft training books where some of ...

Is seven inner joins in a query too much?

I have a query that has 7 inner joins (because a lot of the information is distributed in other tables), a few coworkers have been surprised. I was wondering if they should be surprised or is having 7 inner joins normal? ...

T-SQL: How to get user-defined data-type of the column by it's ID or smth?

I have the query like this SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'OrderId' ORDER BY TABLE_NAME GO OrderId column is of user-defined data type. But DATA_TYPE in the query shows underlying system type (i.e. bigint). How to show user-defined type name? ...

Define table names for results of multiple SQL selects in a single query

For example if I run the following query: select * from table1 select * from table2 And run it with a DB adapter (C#) I get a dataset with two tables. How can I define the names for the result tables in SQL? I can only do this inside the SQL. I don't have access to the c# code. ...

Mysql Offset Infinite rows

I would like to construct a query that displays all the results in a table, but is offset by 5 from the start of the table. As far as I can tell, MySQL's LIMIT requires a limit as well as an offset. Is there any way to do this? ...

best practice for retrieving data which meet selected conditions

Hi, I have a database table named call with columns call_time, location, emergency_type and there are three types of emergency: paramedics, police and firefighters. In the windows form I created CheckBoxes 'paramedics', 'police', 'firefighters' and I want to retrieve all table columns which meet user's selection. I created a function: ...

What is the best way to calculate page hits per day in MySQL

On my blog, I display in the right nav the 10 most popular articles in terms of page hits. Here's how I get that: SELECT * FROM entries WHERE is_published = 1 ORDER BY hits DESC, created DESC LIMIT 10 What I would like to do is show the top 10 in terms of page hits per day. I'm using MySQL. Is there a way I can do this in the database...

Is there an easy way to plot Polyline Area, i.e. service coverage area, and also check to see if visitor's address lies within that area using Google Maps API and PHP?

Hello. I am the owner of a business that is building a new website application. My partner is the programmer who is doing the development and neither one of us has any real in-depth experience with Google Map API or it's polyline/polygon area capabilities. We need an easy way to capture inputs within our user admin area where our locati...

The best way to check if SQL CE is installed, and if so what version?

I've written a VB.NET application that uses SQL CE 3.5. I'm curious if anyone has any best practice or code to help check if A) SQL CE is installed and B) If so, what version. I searched msdn and google for anything but I didn't find anything helpful. I was poking around the registry and found this key: HKEY_LOCAL_MACHINE\SOFTWARE\...

Why use "Y"/"N" instead of a bit field in Microsoft SQL Server?

I'm working on an application developed by another mob and am confounded by the use of a char field instead of bit for all the boolean columns in the database. It uses "Y" for true and "N" for false (these have to be uppercase). The type name itself is then aliased with some obscure name like ybln. This is very annoying to work with for...

How do i backup a SQL database using PHP?

How do i backup a SQL database using PHP. Is there a vendor agnostic way to do this that conforms to ANSI SQL? If not maybe you can list how to do it for each of the database vendors? ...

Hierarchical tagging in SQL

I have a PHP web application which uses a MySQL database for object tagging, in which I've used the tag structure accepted as the answer to this SO question. I'd like to implement a tag hierarchy, where each tag can have a unique parent tag. Searches for a parent tag T would then match all descendants of T (i.e. T, tags whos parent is T...

Calculate mode (or frequency) distribution of a value over time in SQL Server

Given the following table, how does one calculate the hourly mode, or value with the highest frequency by hour? CREATE TABLE Values ( ValueID int NOT NULL, Value int NOT NULL, LogTime datetime NOT NULL ) So far, I've come up with the following query. SELECT count(*) AS Frequency, DatePart(yy, LogTime) as [Year], DatePart...

Python MySQL Statement returning Error

hey, I'm very new to all this so please excuse stupidity :) import os import MySQLdb import time db = MySQLdb.connect(host="localhost", user="root", passwd="********", db="workspace") cursor = db.cursor() tailoutputfile = os.popen('tail -f syslog.log') while 1: x = tailoutputfile.readline() if len(x)==0: ...

Using IN or a text search

I want to search a table to find all rows where one particular field is one of two values. I know exactly what the values would be, but I'm wondering which is the most efficient way to search for them: for the sake of example, the two values are "xpoints" and "ypoints". I know for certain that there will be no other values in that field...

relational terminology: foreign key source, destination?

I'm doing some FK analysis of our tables by making a directed graph representing FK dependencies and then traversing the graph. In my code, I name everything using directed graph terminology, but I'd like to have something a bit more "user friendly" in the report. In this scenario: create table t1(a varchar2(20)); alter table t1 add c...