database-queries

What simple database can I use to store and query data just for myself?

I have come across various situations, where I want to store some formatted data in a way such that it can be easily queried. For example $ cat so.txt "question_id": 58640, "tags": ["polls", "fun", "quotes"], "title": "Great programming quotes" "question_id": 184618, "tags": ["polls", "fun", "comment"], "title": "What is the best comme...

Identity columns for multitenant database schemas

I'm creating a multitenant app where some of the tables need to have sequentially assigned integer values. The ordering is done independently for each tenant. As a concrete example, consider a Student table with a RegNumber column. RegNumber has to be assigned sequentially, but the sequence is local to each tenant. The solution I'm thin...

many to many select query

I'm trying to write code to pull a list of product items from a SQL Server database an display the results on a webpage. A requirement of the project is that a list of categories is displayed at the right hand side of the page as a list of checkboxes (all categories selected by default) and a user can uncheck categories and re-query th...

Optimizing Python Code for Database Access

Hi, I am building an application with objects which have their data stored in mysql tables (across multiple tables). When I need to work with the object (retrieve object attributes / change the attributes) I am querying the sql database using mysqldb (select / update). However, since the application is quite computation intensive, the e...

How do I insert into a database only if a value has changed?

I need to update (replace) fields in a MySQL database, but only if they have changed. The table contains an ID, text field and date changed. Users query the data by ID based on the date it was changed. i.e. If the date is before the last the time user queried the data, he doesn't want it. I would like to change the date in the data...

Multiple row update in nhibenrate

Hi guys, So I was wondering whether it is best to update multiple rows in a database using an hql query or calling nhibernates save after modifying each object.. I know that the answer is the HQL query but please give me adequate reasons for the same. but there are disadvantages of using an HQL query right like my API has a hard depend...

CQRS Command and domain state

Hello, I am new to CQRS and confused on how command will write a address change to a customer object Lets say I have divided customer information into two tables customer - Domain database Active Preferred Customer_Read database Name, Address, Phone, email User modifies address of the customer. The address fields are all in re...

retrieval of multiple images from the database using jsp-servlet

Have a look at the following code snippet. response.setContentType("image/gif"); String url="jdbc:oracle:thin:@localhost:1521:xe"; String username="xyz"; String password="abc"; Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn=DriverManager.getConnection(url,username,password); String sql="Select name,description,im...

What is the equivalent of IBM's SYSIBM.SYSTABLES in Oracle?

Hi, What are the equivalent of SYSIBM. in Oracle? ...

count number of tuples without COUNT. Is it possible?

Hi, I would like to know if there is any way of counting the number of tuples in a table without actually using the COUNT function? A B C XXXX YYYY IIII XXXX SSSS PPPP RRRR TTTT FFFF KKKK AAAA BBBB If I would like to know how many times XXXX has appeared with...

Is there a more efficient way to run queries inside a loop? Memory issues.

I have a Joomla website that I've written a custom shopping cart component for. The user is basically purchasing codes we're storing in our database - these are associated with a printed incentive card. When the user checks out, I need to grab a chunk of codes from the database (however many they've purchased), then loop through the lis...

String concatenation issue in CTE SQL

I have the following CTE SQL WITH Tasks AS ( SELECT TaskID, ParentTaskID, CAST(SortKey AS nChar) AS sort_key /*,cast(SortKey as char) as sort_key */ FROM oaTasks AS s WHERE (TaskID = 1) UNION ALL SELECT s2.TaskID, s2.ParentTaskID ,Cast( '0.'+ cast(Tasks_2.sort_key as...

Count Distinct with NULL retention

Hello, I am using SQL 2005 and having a simple query as below trap duplicates: SELECT x,y,COUNT(DISTINCT z) AS z_count FROM tblA GROUP BY x,y HAVING (COUNT(DISTINCT z) > 1) Now the issue is this column z is sometimes having NULL values, which get ignored by count distinct. As such, duplicates having z as NULL in one record and as ...

Need help with a SQL query that returns the lasts records matching a certain criteria.

I have the following table: CREATE TABLE "posting" ( "id" integer NOT NULL PRIMARY KEY, "amount" real NOT NULL, "balance" real NOT NULL, "account_id" integer NOT NULL REFERENCES "account" ("id"), "asset_type_id" integer NOT NULL REFERENCES "asset_type" ("id") ) For this table, I manually generate ids in a w...

Need help on MySQL DISTINCT+COUNT query

I have a table called "r", inside that table I store id, ip, and country. I am running this query: SELECT r.country, count(rr.ip), count(DISTINCT rr.ip) FROM `r` LEFT JOIN r rr ON r.country = rr.country GROUP BY r.country I do get rows with columns: "country";"number";"number"; But both "counts()" doesn not show what I want it to...

How large can the array passed to SQL where column_value IN (Array) be?

I am writing some code that will lookup for unique id's in a table with over 60,000 rows for the ones that are in an array using mysql_query("SELECT * FROM users WHERE unique_indexed_user_id IN('".join("', '", $array)."')") ; the amount of this array is not limited to the end user so they might end up selecting a large array. thus I...

SQLITE corruption?- DELETE FROM toolList WHERE toolId=".$id

something is seriously wrong with my SQLITE I included echo $dbquery to see exactly what query is being run, and the statment seems correct - but when trying to view the db after, it comes up blank! I've checked the actuall file, and theres still data in the db file, so maybe it corrupting it? the query prints as: DELETE FROM tool...

Database Performance Solution - "View Caching" - Is this a good idea?

Hi, A little context first: I would say I have good SQL server experience, but am a developer, not a DBA. My current task is to improve on the performance of a database, which has been built with a very heavy reliance on views. The application is peppered with inline sql, and using Tuning Advisor only suggests a couple of missing index...

MySQL date range SELECT + JOIN query using column with CURRENT_TIMESTAMP

I am using this query: SELECT p.id, count(clicks.ip) FROM `p` LEFT JOIN c clicks ON p.id = clicks.pid WHERE clicks.ip = '111.222.333.444' To select clicks from table "c", that has "pid" = "p.id". The query seems to work fine, but now I want to use that query with date ranges. The "c" table has a column "time" that uses MySQL CURRENT_T...

Is there any way given a column, which table it belongs using SQL Query?

Is there any way given a column, which table it belongs using SQL Query? ...