database-queries

SQL Dynamic query for searching

I am working on a problem that I'm certain someone has seen before, but all I found across the net was how not to do it. Fake table example and dynamic searching. (Due to my low rating I cannot post images. I know I should be ashamed!!) Clicking the add button automatically creates another row for adding more criteria choices. (Note...

ASP.NET Compiled vs Uncompiled DB qualifiers

We have an ASP.NET application that uses SQL statements, where table names are unqualified. When compiled, it works fine, but when uncompiled, it complains and errors out, saying these tables dont' exist. (Qualified name looks like Select * from MyDatabase.mySchema.MyTable ; Unqualified like Select * from MyTable) If you try these q...

Database Security Queries

You are the DBA for the VeryFine Toy Company and create a relation called Employees with fields ename, dept, and salary. For authorization reasons, you also define views EmployeeNames (with ename as the only attribute) and DeptInfo with fields dept and avgsalary. Show the view definition statements for EmployeeNames and Dept...

Help With Database Layout

Hello everyone, I am working on a site similar to Craigslist where users can make postings and sell items in different cities. One difference between my site and Craigslist will be you will be able to search by zip code instead of having all of the cities listed on the page. I already have the ZIP Code database that has all of the city,...

SQL Complicated Group / Join by Category

I currently have a database structure with two important tables. 1) Food Types (Fruit, Vegetables, Meat) 2) Specific Foods (Apple, Oranges, Carrots, Lettuce, Steak, Pork) I am currently trying to build a SQL statement such that I can have the following. Fruit < Apple, Orange Vegetables < Carrots, Lettuce Meat < Steak, Port I have ...

how to design this relation in a DB schema

I have a table Car in my db, one of the columns is purchaseDate. I want to be able to tag every car with a number of Policies (limited to 10 policies). Each policy has a time to life (ttl, a duration of time, like '5 years', '10 months' etc), that is, for how long since the car's purchaseDate the policy can be applied. I need to perfor...

Can I query inside a SQLite Transaction?

I'm using the SQLite3 database system in the Android library. I need to execute a query during a transaction to see if there is a similar entry already there. If there is, I have to perform some other logic and adjustments before I add a new row. Can I execute a query within a transaction and get the result back immediately? ...

Minimizing calls to database in rails

Hi guys, i am familiar with memcached and eager loading, but neither seems to solve the problem i am facing. My main performance lag comes from hundreds of data retrieval calls from the database. The tricky thing is that I do not know which set of users i need to retrieve until i have several steps of computation. I can refactor my c...

Question regarding the syntax of a php client->call using a soap service

So I am working on a site for work that I "inherited" when I started here, and I am having to swim through a lot of code that i am unfamiliar with, namely soap services. The website has a feature that lets you write some things to the db using this createURL service: $res = $db->Exec('INSERT INTO private_urls (UID, psswrd, profile_id, s...

Searching by key in Apache CouchDB

Is it possible to search by key value in Apache CouchDB? Given the sample data below (spaced for readability): { "_id":"a754a63dcc7f319b02f7ce6de522ca26", "_rev":"1-5bd88e53fe0869b8ce274b49a2c1ddf5", "name":"john smith", "email":"[email protected]", "username":"jsmith" } Could I query the database for the user j...

Nesting, grouping Sqlite syntax?

I can't for the life of me figure out this Sqlite syntax. Our database contains records like: TX, Austin OH, Columbus OH, Columbus TX, Austin OH, Cleveland OH, Dayton OH, Columbus TX, Dallas TX, Houston TX, Austin (State-field and a city-field.) I need output like this: OH: Columbus, Cleveland, Dayton TX: Dallas, Houston, Austin ...

mysql custom sorting first alpha then numeric using case when

How can you sort a query using ORDER BY CASE WHEN REGEXP? or other alternatives? I don't want to use UNION. Thank you mysql> SELECT `floor_id`, `floor_number` FROM `floors`; +----------+--------------+ | floor_id | floor_number | +----------+--------------+ | 1 | 4 | | 2 | 7 | | 3 | G ...

.NET threading solution for long queries

Senerio We have a C# .Net Web Application that records incidents. An external database needs to be queried when an incident is approved by a supervisor. The queries to this external database are sometimes taking a while to run. This lag is experienced through the browser. Possible Solution I want to use threading to eliminate the simu...

How to figure out which record has been deleted in an effiecient way?

Hi, I am working on an in-house ETL solution, from db1 (Oracle) to db2 (Sybase). We needs to transfer data incrementally (Change Data Capture?) into db2. I have only read access to tables, so I can't create any table or trigger in Oracle db1. The challenge I am facing is, how to detect record deletion in Oracle? The solution which I ...

Recommended book for SQL Server query optimisation

Even if I have made a certification exam on SQL Server Design and implementation, I have no clue about how to trace/debug/optimise performance in SQL Server. Now the database I built is really business critical, and getting big, so it is time for me to dig into optimisation, specially regarding when/where to add indexes. Can you re...

sql combine two subqueries

I have two tables. Table A has an id column. Table B has an Aid column and a type column. Example data: A: id -- 1 2 B: Aid | type ----+----- 1 | 1 1 | 1 1 | 3 1 | 1 1 | 4 1 | 5 1 | 4 2 | 2 2 | 4 2 | 3 I want to get all the IDs from table A where there is a c...

retrieving second most highest value from the table

how do i retrieve the second highest value from the table ...

Data View Concept/Library/Pattern ?

Any application that deals with data, has one screen or more to allow the user to look at data. Usually we dont offer all the 10 million records to look at, but a subset, defined by a filter (or a view) that the user can create (and save). How to define these views that are translated (behind the scene) into some kind of "select from xxx...

Integer comparison in mysql using an index

I need to compare integers in a mysql table. Pretty simple, but this table is fairly large... so queries take a long time. No problem, I can use an index. According to MySQL documentation, I should be able to use an index for comparison operators: "A B-tree index can be used for column comparisons in expressions that use the =, >, >=,...

how is this table updated if there is no model file?

I'm trying to manually update a db in Spree, but it has no model file. I want to know how to CRUD into the option_values_variants table. The code uses James Golick's Resource Controller, but I want to do it without. models/option_value.rb class OptionValue < ActiveRecord::Base belongs_to :option_type acts_as_list :scope => :option...