sql

Grouping parents containing the same set of children

I have this parent-child relationship Paragraph --------- ParagraphID PK // other attributes ... Sentence -------- SentenceID PK ParagraphID FK -> Paragraph.ParagraphID Text nvarchar(4000) Offset int Score int // other attributes ... I'd like to find paragraphs that are equivalent; that is paragraphs tha...

Changing order of selects in stored proc affects SSIS hang issue

I am using an OLEDB source to call a stored proc to grab a set of rows each marked with either I U or D by doing a UNION between three SELECT statements in a stored procedure. A is a table populated with data brought over from a legacy system every night. B is our system's data we want to keep updated with the legacy system's data. SET...

Comparing Dates in Openoffice Database with HSQLDB

I have a table in an Openoffice Database, containing two date columns. I'm trying to create a view that will aggregate all the rows in these columns and sum up the difference between these two columns in minutes. This is pretty trivial, and in Postgres it would look like: SELECT SUM(EndDate-BeginDate) AS total_minutes FROM mytable Wh...

SQL Group By question - choosing which row gets grouped

I have a table that tracks serial numbers and the number of licenses associated with said serial number. A client can re-license a box, increasing or decreasing the number of users, and they are only billed for the changed amount. The following table structure exists: id - Auto Incrementing ID serial - The serial number numusers - the ...

Count of distinct rows with duplicate email IDs

Hello, How do I get count of distinct rows with duplicate email IDs in SQL? ID NAME EMAIL 1 John [email protected] 2 Sam [email protected] 4 Bob [email protected] 5 Tom [email protected] 6 Rob [email protected] 7 Tic [email protected] 8 Dad [email protected] The query should return 2. as [email protected] and [email protected] are duplica...

mysql WHERE '2010-08-24 11:59:59' BETWEEN c.start_date AND c.end_date;

I'm currently trying to use this query SELECT a.id AS id, a.item AS item, c.id AS campaign_id, DATE(c.start_date) AS START, DATE(c.end_date) AS END FROM campaign c LEFT JOIN action_6 a ON c.id = a.campaign_id WHERE action_id = 6 AND TIMESTAMP('2010-08-24 11:59:59') BETWEEN c.start_date AND c.end_date; however i am getting an empty ...

This query doesnt appear to work? Looks ok to me....

$q = "UPDATE ".TBL_LEAGUETABLES." SET home_games_played = home_games_played + 1, home_wins = home_wins + '$w', home_draws = home_draws + '$d', home_losses = home_losses + '$l', ...

How can I specify sql sort order in sql query

Hi, I have the follow SQL query statement: SELECT subject, sender_list, date, uid FROM messages WHERE folder_id = 3 Can you please tell how can I specify query sort order? Thank you. ...

Oracle: How do I grab a default value when a more specific value is null from within the same query?

That title is brutal, but I don't know how else to put it. I have a key value table tied to a user_id that stores user preferences throughout the site. If a user hasn't gone in and updated any of their settings, any time I ask for a key (say "FAVORITE_COLOR" it's going to be null, so I need to pull the default setting that I have tied ...

Get data origin after a UNION

I have a SQL query like this: SELECT * FROM ( (SELECT name FROM man) UNION (SELECT name FROM woman ) ) AS my_table ORDER BY name how can I retrieve the source of my data? For example if my result is like this: Bob Alice Mario ... I want to know if the name 'Bob' is retrieve from the 'man' table or from the 'woman' table. ...

Select results from the middle of a sorted list?

I've got a simple table with 300 rows, and after ordering them I want to select rows 11-50. Do I limit by 50 and remove the top 10 rows somehow? ...

Update a column in a table with values from two other tables

Hi, I have to update a column in Table 'A' with values from Table 'B'. If any value in Table 'B' is null or empty then I have to get the value from table 'C'. Manu ...

SQLCMD: Prompt for Variable?

Coming from an Oracle background, Oracle's SQLPlus would let you indicate a variable. If the variable wasn't set, you'd be prompted to provide a value. I'm using SQLCMD, using the $([var_name]) syntax. In SSMS SQLCMD mode, I get: A fatal scripting error occurred. Variable tbl_name is not defined. ...for trying to run: SELECT ...

Select top 1 for each group

I have an Access database that contains a table with information about parts we sort. This table has an autonumber ID field and a 110ID that links to another table with the part information. It also contains a sortDate, sortShift, sorted, scrapped, and repaired. I need to find how many parts have been sorted since the last defect (non...

Ms Access gives rubbish when updating a join column

Updating a column that is part of your selection criteria should be no problem I think/thought. I still have a query that gives odd results: update table1 as t1 inner join table2 as t2 on t1.id = t2.old_id set t1.id = t2.id I use table2 to map id to old_id. table1.id and table2.id are both primary keys. table2.old_id is also unique. ...

redundant column

Hi there, I have a database that has two tables, these tables look like this codes id | code | member_id 1 | 123 | 2 2 | 234 | 1 3 | 345 | 4 | 456 | 3 members id | code_id | other info 1 | 2 | blabla 2 | 1 | blabla 3 | 4 | blabla the basic idea is that if a code is taken then its member id field is fil...

sql, selecting the lastest completed couse using max (column name) not working

Every year employee takes mandatory courses. I need to get a list of employees and their latest completed course, for example FS (fire safety). Below is my query. The problem is it shows two or three completed courses for some employees. Trying to troubleshoot those employees’s record, it shows the latest completed course, when I se...

How to execute two MySQL queries ?

I want to save the file path of a picture, AND the image name, in the same table, but separate fields of course. How can I execute it properly? I'm sure there is something significantly wrong in the code below, but I can't spot it. Thank you. $sess_userid = mysql_real_escape_string($_SESSION['userid']); $Image = mysql_real_escape_string...

TSQL multiplying different datatypes

How can I multiply two types? I have one column with cost of type money. Another column that has the number of those products of type integer. How can I multiply these two values to result in a value representing the cost? Example: $2000 * 2 ...

Tool to generate data dictionary from SQL file

Ok, so I got duped into doing some database design for an Oracle database where I work. The problem is, I'm not much of a DB guy :-). I'm currently using Rational Application Developer (RAD) to do the modeling of my database schema. What I'd ideally like to do is generate a series of Word documents, containing information from my DB sche...