database-queries

select categories with parent name from one table

Hello, I got an existing products database which I'm writing an administration tool for (in PHP). The database contains the following "categories" table: Table Categories -------------------- PK | id FK | parent_id | title Now the foreign key "parent_id" contains an id taken from the same table, or "0" if it's a topmost category. ...

Best way to store user permissions?

Hey all, Designing a fairly complicated site with a lot of ajax running on a single page. I have reached the point where some user's need to have specific permission to do things and some need to be stopped from the action. I have set up user roles in my database and all is working fine, but I wonder if there is an easier/safer method f...

Split Multiple Columns into Multiple Rows

I have a table with this structure. UserID | UserName | AnswerToQuestion1 | AnswerToQuestion2 | AnswerToQuestion3 1 | John | 1 | 0 | 1 2 | Mary | 1 | 1 | 0 I can't figure out what SQL query I would use to get a result set like this: UserID | User...

Best database for a real-time event analytics solution

I'm developing a real-time analytics solution and I need to choose the best database to do it. I believe MongoDB is ideal but I don't have the experience to compare all the other solutions. What's your advice? Thanks ...

Oracle Check Constraint Issue with to_date

So I'm new to Oracle, trying to create a table as follows: create table Movies ( Title varchar2 primary key, Rating NUMBER CONSTRAINT Rating_CHK CHECK (Rating BETWEEN 0 AND 10), Length NUMBER CONSTRAINT Length_CHK CHECK (Length > 0), ReleaseDate DATE CONSTRAINT RDATE_CHK CHECK (ReleaseDate > to_date('1/1/190...

Oracle SQL Issue with Insert Statements

So I am a beginner to this, and trying to follow my professors instructions on how to complete this. They are as follows: Consider the relational database described in Tables 1-3. The underlined attribute(s) is the primary key for a table. Use your Oracle account to create this database and to insert the tuples listed in each table. ...

whats difference between NoSql DB and OO Db?

whats difference between NoSql DB and OO Db? ...

How to UPDATE the same mysql row from multiple scripts at the same time?

I am forking some php scripts and I need to update a mysql row to track some progress. I read that I should use InnoDB for this but I coulnd't find any complete example I can understand. A friend told me he uses this php code: mysql_query("SET AUTOCOMMIT=0;"); mysql_query("START TRANSACTION;"); mysql_query("SET TRANSACTION ISOLATION LEV...

Need help with some Oracle SQL Queries

Here is the question posed by a professor: Find the minimum and maximum length of movies playing in each city. And here is how I have my tables structured: CREATE TABLE Theatres ( Name varchar2(50) not null, City varchar2(50) not null, State varchar2(50) not null, Zip number not null, Phone varchar2(50) not null, PRIMARY KEY (Name) ); ...

ORACLE SQL Statement

So I need help modifying my query to not just include one movie from each city, but all movies from each individual city. Here is my professor's question: Find the average rating of all movies playing in each city. Display the city name and the computed rating. Order the results descending by rating. Here is my definition for each tabl...

Oracle SQL Question

So I've been doing this all night - can't quite understand my homework, and sadly my professor is unavailable on the weekend. Here it goes: Find the titles of the newest movies shown in each city. Display the city name and the newest movie title ordered by city name and movie title. Here are my table declares (and thank you to EVERYONE...

Oracle SQL Question - Need Help

So I've been doing this all night - can't quite understand my homework, and sadly my professor is unavailable on the weekend. I've posted a few of these questions, this being the last one. I've got something to go on, but it needs working (and coming out of this I'd love to fully understand the answer so I don't need help on something ...

Architecture Help: Queries on Subsets

Building an application to calculate metrics on Service Level Agreements. I have access to a single, de-normalized, table that gives me the info I need: ticket ID, category/subcategory, open/close dates, ticket priority, etc. The only way to identify the specific SLA being measured is to select by category and subcategory. Then I need to...

How to pick table in query based on subtype?

I have 4 tables, Transactions, Orders - SuperType, and then Site_Orders and Product_Orders SubType [Transactions] id PK Orders_id [FK Orders.orders_id] [Orders] Orders_id PK Orders_type [Site_Orders] Orders_id [FK Orders.orders_id] == other data == [Product_Orders] Orders_id [FK Orders.orders_id] == other data == My question is, h...

What is pctincrease in oracle?how the memory is allocated,resized,and autoextended while creating a table space

How the memory is allocated,reallocated and autoextended while creating tablespaces?what is meant by initial and default in tablespaces and how the next is a multiple of five times DB_BLOCK_SIZE? ...

how to notify my Program when database updated ?..

Hi there, I have a C# program that queries the database(SQL Server) for some value. Currently the application queries the database every minutes to make sure that the table is up to date. What I would like to be able to do is that the querie is only done when the database has been changed/updated.How do i notify my program when some t...

How to duplicate a table with all its constrains in SQL*Plus?

Using create table tab2 as select * from tab1;, I am able to copy the data but not the primary key constraint : SQL> desc tab1; Name Null? Type ----------------------------------------- -------- ---------------------------- ID NOT NULL NUMBER NAME ...

Avoid huge intermediate query join result (1.33615E+35 rows)

I need a query to prevent a join that produces 1.34218E+35 results! I have a table item (approx 8k items; e.g. Shield of Foo, Weapon of Bar), and each item is one of 9 different item_type (Armor, Weapon, etc). Each item has multiple entries in item_attribute (e.g. Damage, Defense). Here is a pseudo-code representation: Table item ( it...

php mysql query: multiple drop down options

I have a search box that the user can select a $location a $type and a $rating. $result = mysql_query("SELECT * FROM Places WHERE Location = '$location' and Type ='$type' and Rating = '$rating'") or die(mysql_error()); This works fine if the user selects and option from all 3 drop down boxes- however how do I make the msql query che...

How do you set a has_one default value in ActiveRecord?

I have something like this: class User < ActiveRecord::Base has_one :profile end class Profile < ActiveRecord::Base belongs_to :user end user = User.new user.profile.something #=> ERROR What is a proper way to set a default profile object in this case? I have tried this: class User < ActiveRecord::Base default_scope :include...