sql

MySQL: Include COUNT of SELECT Query Results as a Column (Without Grouping)

I have a simple report sending framework that basically does the following things: It performs a SELECT query, it makes some text-formatted tables based on the results, it sends an e-mail, and it performs an UPDATE query. This system is a generalization of an older one, in which all of the operations were hard coded. However, in pushing...

MySql Select statement distinct latest date value based on Primary ID of Keyword

Basically I have a list of SEO keywords in one table and their Ranking including Date entered in another table. keywords [keywordID(PKID)] [keyword] ---------------------------- 1 SEO 2 Vancouver Homes keywordRanking [rankingID(PKID)] [keywordID(FKID)] [ranking] [rankingDate(timestamp)] --------------...

SQL Query to find missing rows between two related tables

I have two tables: Table A ID ABC_ID VAL Table B ID ABC_ID VAL These two tables are directly related to each other through the ABC_ID column. I want to find all the VAL column values in table A which are not present in table B for the same ABC_ID. ...

SQL Sub Query Help

I am having trouble with a homework question. Specifically, find the maker(s) who produce(s) a PC faster than all laptops. The query I am using is SELECT DISTINCT maker From Product Where model = (SELECT model FROM PC WHERE speed > ALL (SELECT speed ...

Matching delimited string to table rows

So I have two tables in this simplified example: People and Houses. People can own multiple houses, so I have a People.Houses field which is a string with comma delimeters (eg: "House1, House2, House4"). Houses can have multiple people in them, so I have a Houses.People field, which works the same way ("Sam, Samantha, Daren"). I want ...

Loading million rows in hibernate

If I want to fetch million rows in hibernate, how would it work? Will hibernate crash? How can I optimize that. ...

PostgreSQL: how to combine multiple rows?

I have a table like this to save the results of a medical checkup and the date of the report sent and the result. Actually the date sent is based on the clinic_visit date. A client can have one or more reports (date may varies) --------------------------------------- | client_id | date_sent | result | -------------------------------...

SQL Architecture: Is this a justified case to have only one table storing multiple entity types? (using a self JOIN)

I rarely come across a situation where a single table for multiple entity types seems better than one table per entity type. Here's an example that makes sense to me, but academically it seems wrong. QUESTION: Can I do this and still have a "sound" architecture? Example Follows Suppose two entity types, a corporation and a person. A c...

INSERT query is not letting me post data to database

I'm trying to implement a comment.php script that takes the data from a html textfield and save it to a database in phpmyadmin. I implemented registration.php, which is longer and it inserts new users flawlessly. Now the comment.php, which is simpler is not adding anything to a comments table. Here's the code for comment.php: <?php ...

How make this sql. ( conditions sql )

Query: SELECT * FROM Post ORDER BY Post.rating <-- Here , i want ( Post.rating * 5 ) when Post.recommended = 1 ) Thanks all people. ...

Can you create a case statement in select command that evaluates two different table fields?

SELECT HQRH_BADGENO, HQRH_SHIFT, HQBD_BADGENAME, HQRH_DISCRRECONCILE, HQRH_ADJUSTAMOUNT, HQRH_DISCRADJUSTMENT, CASE HQRH_DISCRRECONCILE WHEN 'HQRH_DISCRRECONCILE <0' THEN 'HQRH_ADJUSTAMOUNT' WHEN 'HQRH_ADJUSTAMOUNT>0' THEN 'HQRH_ADJUSTAMOUNT' WHEN 'H...

how to check type of value in postgres

I want to check type of value in postgres like this: SELECT id, CASE WHEN val_is_integer THEN (SOME_QUERY) WHEN val_isnot_integer THEN (ANOTHER_QUERY) ELSE 0 END FROM test; How to do that? notes: the value is varchar type in table, and in that field there is value is numeric and varchar ....

string to oracle date in java

Hi... I have a string in the format "dd.mm.yyyy hh:mm".. i need to convert it into oracle date format 'dd-mon-yy'..... How do i make it happen??? ...

RE: How make this sql. ( conditions sql )

I questioned here this: http://stackoverflow.com/questions/3827690/how-make-this-sql-conditions-sql but now, I want SELECT SUM( Post.rating ) as countRating <--- THIS i want Post.rating * 5 WHEN Post.recommended = 1 FROM posts as Post ORDER BY countRating DESC help me ...

Using prepared statement without ROW_NUMBER() and OVER() functions in Db2.

Let's say I have a table T_SWA .This is my prepared statement. Select version from (Select id, version,creator,created_date ROW_NUMBER() OVER(order by created_date) cnt From T_SWA where cnt=3 and id=35); I need to select the 3rd recent version from the T_SWA table..Can anyone suggest a replacement for this query without using ROW_NUM() ...

Storing an IP as an unsigned int?

I read that the best way to store IP addresses in a database is to make an Unsigned Int(10) field. How do I convert the IP addresses using PHP? I've tried using $this->ip = long2ip($_SERVER['REMOTE_ADDR']); But this doesn't seem to work. I found the way to convert it back to an IP address using $this->ip = sprintf("%u", ip2long($resu...

How to like two columns in one SQL statement

Table A Column aa ----- jack jim alan Table B Column bb ----- jacky jimmy william output is: ----- jack jacky jim jimmy because aa's value is bb's substring. How to write this SQL? ...

Python DB-API: how to handle different paramstyles?

I'm implementing a Python ontology class that uses a database backend to store and query the ontology. The database schema is fixed (specified in advance), but I don't know what type of database engine is being used. However, I can rely on the fact that the Python interface of the database engine uses the Python DB-API 2.0 (PEP 249). A s...

Find Similar Rows in Database

I try to design my app to find database entries which are similar. Let's for example take the table car (Everything in one table to keep the example simple): CarID | Car Name | Brand | Year | Top Speed | Performance | Displacement | Price 1 Z3 BMW 1990 250 5.4 123 23456 2 ...

SQL select print out results of stored procedue

My businesses application supports only reporting with selected data from SQL server.In one business process I have very complicated stored procedure which using others stored procs and it was designed to print out results as log of job done. What I want to catch that print out and select it as varchar(max) so my app can handle that data...