sql

MySQL: Code To Compare 2 Tables, Then If row is the same update Master Date

I have two tables, they are called MASTER and NEWDATA. The schema on both tables is exactly the same and they contain the field names: CODE, SERIAL, MODEL, VALIDATED_DATE. I want to check if the values in the CODE field exists in the NEWDATA table and in the MASTER table. If they are in both tables, then I want to update the VALIDATED_D...

A query: select * returns data, but select Column does not return results

I have a query like this: select pln.* from plan pln where pln.id = '0003' and pln.seq = (select max(pln_es.seq) from plan pln_es where pln_es.id = pln.emplid and pln_es.career =pln.career and pln_es.nbr = pln.nbr and pln_es.d...

Mysql: How do you create a table with multiple primary keys?

I have this situation: http://stackoverflow.com/questions/1590033/mysql-newbie-question-which-are-the-pk-and-the-fk-for-this-tables (take a look at the table Salaries) How do you create a table with multiple primary keys? create table salaries ( dep_id smallint auto_increment primary key, emp_id smallint auto_increment primary ke...

MySQL InnoDB locking only the affected rows?

I have an InnoDB table containing users, like this: +--------------+-----------------------+ | user_id | name | +--------------+-----------------------+ | 1 | Bob | | 1 | Marry | | 2 | Bob | | 1 | John |...

How to return zero using Count() with multiple tables

i have three tables (SQL Server) Month - month_id, month name, .... Award - award_id, award name, .... Nomination - fk_award_id, fk_month_id, name, address,... I need to count the number of different types of awards awarded per month while returning 0 in cases where nobody is awarded for ex. the results should look like A...

sort postgres table data in php through array

I have a postgres database with a table called workorders. In it is a column called date_out where the date is recorded like 2009-09-23. I want to sort this table data in a php page based on a users date range, ie, sort the table by date begin 2009-09-01 end 2009-09-31. Its for an accounts package I am creating for my company. Is there a...

How to mark counted rows as deleted? contin'd from previous question

Ok I just realized that from my previous question: http://stackoverflow.com/questions/1590370/update-main-table-based-on-rows-from-a-secondary-table That was how to update the main table with the count using the secondary table, but since this query will be in a sql job, how can I delete the rows I just counted, and making sure I don't ...

Delete all rows in a table based on another table

I can't seem to ever remember this query! I want to delete all rows in table1 whose ID's are the same as in Table2. So: DELETE table1 t1 WHERE t1.ID = t2.ID I know I can do a WHERE ID IN (SELECT ID FROM table2) but I want to do this query using a JOIN if possible. ...

How do I sort a VARCHAR column in SQL server that contains words and numbers?

I have a varchar(100) field that contains both letters and numbers. The values are usually in the form of car 1, car 10, car 100, car 20. But the values can have any word preceding the number. Is there any way to sort these values numerically so that car 2 will come before car 10? Thanks. ...

Report Server option on SQL Server Management Studio Express?

I want to connect to a SQL Server Reporting Services Report Server from SQL Server Management Studio Express. Unfortunately there is no "Report Server" option in the "Server Type" drop down. Am I missing something here? ...

why can't I access my CTE after I used it once?

My stored procedure looks like: WITH MYCTE(....) AS ( ... ) UPDATE ... (using my CTE) DELETE ( using my CTE) <--- says the object, my CTE, doesn't exist Can I only use it once? ...

SQL: joining 3 tables, needing to also join the 3rd to itself

This works if I remove the final JOIN line, but I'm not sure why it won't work with it. The last two JOIN statements are attempting to grab data ('meta_value') from different rows in the same table, the names of which can only be found by reading another corresponding column ('meta_key') in the same table. All this while joining everythi...

Classic ASP Parameters passing nulls (or empty parms) and ordering

I'm using classic ASP and trying to create parameters for a stored procedure call for a procedure that has optional (=NULL) parameters. One of the parameters, @maxrows, is required. When I try to pass via the following call: With objCommand .ActiveConnection = oConn .CommandText = "usp_client_onsite_search" .CommandType = adCmdStoredPr...

Two left joins and one query to MySQL performance problem

Hello, I'm designing a project for quizzes and quizz results. So I have two tables: quizz_result and quizz. quizz has primary key on ID and quizz_result has foreign key QUIZZ_ID to quizz identity. Query below is designed to take public quizzes ordered by date with asociated informations: if current user (683735) took this quizz and has...

Oracle - difference or changes between two rows from two tables

I have two tables both have same schema, one will have previous day records other will have current. I want to compare both and find only changes or only rows that have different value in atleast one column. How is this possible in pl/sql, oracle? (I did code something similar using checksum in T-SQL but not sure how to do in pl/sql) ...

Concatenating records in a single column without looping?

I have a table with 1 column of varchar values. I am looking for a way to concatenate those values into a single value without a loop, if possible. If a loop is the most efficient way of going about this, then I'll go that way but figured I'd ask for other options before defaulting to that method. I'd also like to keep this inside of ...

How do I list all the available views of a particular table in SQLite ?

I want to access all the particular views of any particular table in Sqlite . I know I can get the list of all the available tables in the database using sqlite_master SELECT name from sqlite_master WHERE type='table'; And the list of all the available views using SELECT name from sqlite_master WHERE type ='view'; But I want to f...

Pivot / unpivot in SQL

Hi, I have a view in SQL that I have generated by analysing the values in tables so that field either contain the value 'N', 'D' or 'V'. I can work out the totals by column but not by row... Is this possible? Example: Data No, Col_1, Col_2, Col_3 1, N, N, N 2, N, D, D 3, N, V, D 4, V, ...

Is `Delete From Join` Standard SQL?

Among other questions, this one asked how to delete from a join. My question: How much of this is standard SQL? On which databases would this actually work (most notably for me would be Oracle, MySQL and SQLServer)? ...

MySQL - Create an UNIQUE index on two columns for ON DUPLICATE KEY

I have a table with 4 columns. I want to be able to INSERT or UPDATE the value column on creation (I don't care about indexes row ID's). CREAT TABLE tablename ( id, (primary) user_id, (index) setting_id, (index) value (index) ); Originally I was going to run a "REPLACE INTO..." query each time I wanted to save a value. But then...