sql

Oracle join query

There are three tables in my db ITEM_MASTER, PRICE_MASTER, COMP_MASTER ITEM_MASTER STORE_CODE ITEM_CODE ITEM_DESC 011 914004 desccc PRICE_MASTER STORE_CODE ITEM_CODE COMP_CODE 011 914004 01 011 914004 02 011 914004 03 011 914004 04 COMP_MASTER COMP_CODE CO...

Is there a way to optimize this update query?

I have a master table called "parent" and a related table called "childs" Now I run a query against the master table to update some values with the sum from the child table like this. UPDATE master m SET quantity1 = (SELECT SUM(quantity1) FROM childs c WHERE c.master_id = m.id), quantity2 = (SELECT SUM(quantity2) FROM childs c ...

SQLAlchemy: select over multiple tables

Hi, I wanted to optimize my database query: link_list = select( columns=[link_table.c.rating, link_table.c.url, link_table.c.donations_in], whereclause=and_( not_(link_table.c.id.in_( select( columns=[request_table.c.recipient], whereclause=request_table.c.donator==donator.id ...

reset all logged in users after they shutdown their consoled

i have list of student who have Nintendo DSs, and they should log in my website to solve some sheets (by using DS Opera browser), when they logged in , (status filed at my DB will change from 0 to 1),also the status change to 0 if they log out, what i need is when the student didn't log out and Shut down their DS's , the status should be...

How to Avoid Duplicate Key Exception

I am using TableAdapter to insert records in table within a loop. foreach(....) { .... .... teamsTableAdapter.Insert(_teamid, _teamname); .... } Where TeamID is the primary key in the table and _teamID inserts it. Actually i am extracting data from XML file which contains unique teamId After first run of this loop, Insert thr...

Problems with mysql syntax

I´m trying to create a trigger on MySQL but I´m having a syntax problem, which I was not able to find. If someone more experience could help me it would be great (it´s the first time I use MySQL!)... The reason why I´m creating this trigger is for deleting all the orphan "labels", which has a many-to-many relation with "service_descript...

Wordpress SQL query help (list posts from specific category)

I want to list those posts from wp_posts whose term_id is 38 , but i have a problem , term_id is stored in different table which is wp_term_taxonomy and wp_pst is different table, how can i search the particular record from these two tables ? If term_id inside wp_term_taxonomy is 38 then show the records from wp_posts...how can i do this...

IP address numbers in MySQL subquery

I have a problem with a subquery involving IPV4 addresses stored in MySQL (MySQL 5.0). The IP addresses are stored in two tables, both in network number format - e.g. the format output by MySQL's INET_ATON(). The first table ('events') contains lots of rows with IP addresses associated with them, the second table ('network_providers') c...

Adding views to a vendor-delivered database and performance

We have a vendor delivered database that to this point I have been able to avoid making any database structure changes to. We will be soon directly querying the tables directly for a related project. In order to pull all of the data we need, we will need to create a big SQL statement with multiple unions. select ... from table1 union s...

Help with this JET Sql Query [SOLVED]

Hi: I need help to do this query select. for example I have these fields: idInvoice date amount Depending of the date I need multiply the field "amount" for x number or other one. For example, if the date is less 01/01/2010 to multiply for 20 . But if it is major or equal to multiply for 35 Select idInvoice, date, amount, amou...

Table names, and loop to describe

Working in Oracle 10g. Easy way to list all tables names (select table_name from dba_tables where owner = 'me') But now that I have the table names, is there an easy way to loop through them and do a 'describe' on each one in sequence? ...

Query a stored procedure for it's parameter names and types

Is there any easy way to query a stored procedure (Oracle - PL/SQL) for what parameters it expects? I know that I can query USER_SOURCE to get the whole procedure but I'd then have to parse the whole procedure, and if the parameter is of type [table].[column]%TYPE I'd then have to query the table schema as well. Either using just sql o...

Is "campaign_$" a bad name for a SQL column?

PostgreSQL has allowed me to name a column "campaign_$". I like the name because it's short and to the point, and other potential names like "campaign_receipts" seem longer and less clear. BUT, I wonder if I'll eventually regret putting a $ symbol in a column name, either in PHP or in some other distant part of the architecture. Shoul...

Is it possible to set a primary key to a view?

Is it possible to set a primary key to a view in SQLServer 2008? ...

Get recursive data with sql server

I am trying to get recursive data. Following code returns all parents on the top and then the children. I would like to get data Parent 1 – his children then parent 2 - his children then parent3 – his children. How do I do this? USE Subscriber GO WITH Parent (ParentId, Id, Name,subscriberID) AS ( -- Anchor member definition SELECT...

How can I translate this SQL statement to a Linq-to-SQL approach?

For example, imagine that I want to see if a user exists in my database: Select * from Users where inputID = Users.ID Then if that result brought > 0 items, then the user exists, correct? How can I do something like this using a pure Linq-to-SQL class? ...

is NATURAL JOIN any better than SELECT FROM WHERE in terms of performance ?

Today I got into a debate with my project manager about Cartesian products. He says a 'natural join' is somehow much better than using 'select from where' because the later cause the db engine to internally perform a Cartesian product but the former uses another approach that prevents this. As far as I know, the natural join syntax is no...

Simple Select Statement on MySQL Database Hanging

I have a very simple sql select statement on a very large table, that is non-normalized. (Not my design at all, I'm just trying to optimize while simultaneously trying to convince the owners of a redesign) Basically, the statement is like this: SELECT FirstName, LastName, FullName, State FROM Activity WHERE (FirstName=@name OR LastName...

How do I find the top N batters per year?

I'm playing around with the Lahman Baseball Database in a MySQL instance. I want to find the players who topped home runs (HR) for each year. The Batting table has the following (relevant parts) of its schema: +-----------+----------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default ...

MS Chart control - Optimize method for displaying 'zero' Y value columns for a Line chart type

I’m using Microsoft Chart extensions that ship with VS 2010. This suits my needs well, but I’ve run into an annoyance and am looking for a more elegant solution. When charting a line graph, to achieve a continuous line, I require data for all X coordinates. My dataset is for number of sales by employee by month, where sales count is o...