The whole question is pretty much in the title. For each row of the table I'd like to select the maximum of a subset of columns.
For example, from this table
name m1 m2 m3 m4
A 1 2 3 4
B 6 3 4 5
C 1 5 2 1
the result would be
name max
A 4
B 6
C 5
The query must be compatible oracle 8i.
Thanks.
I want to get all Images not used by current ItemID. The this subquery but it also always returns duplicate Images:
EDITED
select Images.ImageID, Images.ItemStatus, Images.UserName, Images.Url,
Image_Item.ItemID, Image_Item.ItemID
from Images
left join (select ImageID, ItemID, MAX(DateCreated) x
from Image_Item
where ItemID != '5a0077fe-cf86-434d-9f3b-7ff3030a1b6e'
group by ImageID, ItemID
having count(*) = 1)
image_item on Images.imageid = image_item.imageid
where ItemID is not null
I guess the problem is with the subquery which I can't avoid duplicate rows:
select ImageID, ItemID, MAX(DateCreated) x
from Image_Item
where ItemID != '5a0077fe-cf86-434d-9f3b-7ff3030a1b6e'
group by ImageID, ItemID
having count(*) = 1
Result:
F2EECBDC-963D-42A7-90B1-4F82F89A64C7 0578AC61-3C32-4A1D-812C-60A09A661E71
F2EECBDC-963D-42A7-90B1-4F82F89A64C7 9A4EC913-5AD6-4F9E-AF6D-CF4455D81C10
42BC8B1A-7430-4915-9CDA-C907CBC76D6A CB298EB9-A105-4797-985E-A370013B684F
16371C34-B861-477C-9A7C-DEB27C8F333D 44E6349B-7EBF-4C7E-B3B0-1C6E2F19992C
Table: Images
ImageID uniqueidentifier
UserName nvarchar(100)
DateCreated smalldatetime
Url nvarchar(250)
ItemStatus char(1)
Table: Image_Item
ImageID uniqueidentifier
ItemID uniqueidentifier
UserName nvarchar(100)
ItemStatus char(1)
DateCreated smalldatetime
Any kind help is highly appreciated.
Left outer joins should return at least one row from the T1 table if it matches the conditions. But what if the left outer join performs a join successfully, then finds that another criterion is not satisfied? Is there a way to get the query to return a row with T1 values and T2 values set to NULL?
Here's the specific query, in which I'm trying to return a list of candidates, and the user's support for those candidates IF such support exists.
SELECT c.id, c.name, s.support
FROM candidates c
LEFT JOIN support s on s.candidate_id = c.id
WHERE c.office_id = 5059
AND c.election_id = 92
AND (s.user_id = 2 OR s.user_id IS NULL) --This line seems like the problem
ORDER BY c.last_name, c.name
The query joins the candidates and support table, but finds that it's a different user who supported this candidate (user_id=3, say). Then the candidate disappears entirely from the result set.
I'm currently trying to optimize the sluggish process of retrieving a page of log entries from the SQLite database.
I noticed I almost always retrieve next entries along with count of available entries:
SELECT time, level, type, text FROM Logs
WHERE level IN (%s)
ORDER BY time DESC, id DESC
LIMIT LOG_REQ_LINES OFFSET %d* LOG_REQ_LINES ;
together with total count of records that can match current query:
SELECT count(*) FROM Logs WHERE level IN (%s);
(for a display "page n of m")
I wonder, if I could concatenate the two queries, and ask them both in one sqlite3_exec() simply concatenating the query string. How should my callback function look then? Can I distinguish between the different types of data by argc?
What other optimizations would you suggest?
The whole question is pretty much in the title. For each row of the table I'd like to select the maximum of a subset of columns.
For example, from this table
name m1 m2 m3 m4
A 1 2 3 4
B 6 3 4 5
C 1 5 2 1
the result would be
name max
A 4
B 6
C 5
The query must be compatible oracle 8i.
Thanks.
Hello All,
I dont know how to copy table data from
one server - database - table
TO
other sever - database - table.
If it is with in the same server and different databases, i have used the following
SELECT * INTO DB1..TBL1 FROM DB2..TBL1 (to copy with table structure and data)
INSERT INTO DB1..TBL1(F1, F2) SELECT F1, F2 FROM DB2..TBL1 (copy only data)
Now my question is copy the data from SERVER1 -- DB1-- TBL1 to SERVER2 -- DB2 --TBL2
Thanks in advance!
What data type should I use for data that can be very short, eg. html link (think twitter), or very long eg. html blog post (think wordpress).
I am thinking if I use varchar(4000), it maybe too short for a html formated blog entry? but if I use text, it will take up more space and is less efficient?
Hello I have a database for a certain record where it needs to store a 1 or a 0 for each day of the week. So which one would be better? Bitshifting each bit into an integer and just having an integer in the database named days or should we make all of them separate boolean values so to have sunday, monday, tuesday... columns?
For those of you who live and breath database design, have you ever found compelling reasons to have multiple FK's in a table that all point to the same parent table?
We recently had to deal with a situation where we had a table that contained six columns which were all FK columns to the same parent table. We're debating whether this indicates a poor design on our part or whether this is more common than we think.
Thanks very much.
Hi, all.
I have a table x that's like the one bellow:
id | name | observed_value |
1 | a | 100 |
2 | b | 200 |
3 | b | 300 |
4 | a | 150 |
5 | c | 300 |
I want to make a query so that in the result set I have exactly one record for one name:
(1, a, 100)
(2, b, 200)
(5, c, 300)
If there are multiple records corresponding to a name, say 'a' in the table above, I just pick up one of them.
In my current implementation, I make a query like this:
select x.* from x ,
(select distinct name, min(observed_value) as minimum_val
from x group by name) x1
where x.name = x1.name and x.observed_value = x1.observed_value;
But I think there may be some better way around, please tell me if you know, thanks in advance.
I have the a simple LinqToSQL statement that is not working. Something Like this:
List<MyClass> myList = _ctx.DBList
.Where(x => x.AGuidID == paramID)
.Where(x => x.BBoolVal == false)
.ToList();
I look at _ctx.DBList in the debugger and the second item fits both parameters.
Is there a way I can dig into this more to see what is going wrong?
I am using the insert() function from Zend_Db_Table_Abstract.
The data being inserted is user input, so naturally I am curious if ZF does the data cleansing for me, or if I should do it myself before I call the insert() function.
i have maintained two datas into my table
1 column 2 column
PaidDate validitydate
in padidate ill give insert todaydate. but in validity date i may either insert validity for 1 week/1 month.
I have used validity=DATEADD(Day,7,@paiddate) to insert validity for 1 week. but how to gtet the validity for 1 month from todays date
My database has around 25 core numbers, in that weekly basis I need to create an index and drop index. While creating the index it takes long time to complete, my log file also keeps on increasing, and when I delete some numbers from that table also taking too much time (because weekly basis I have to delete 30 to 50 lack numbers and add 30 to 40 lack new number also).
Can u please give me the proper solution..
Hi ,
I have created Dealer dimension in SSAS 2005 and it has 3 hierarchies. By default the hierarchy created first is the default hierarchy of the dimension.
Is there any way to change the default hierarchy to another hierarchy.
I am trying to add the SQL_CALC_FOUND_ROWS into a query (Please note this isn't for pagination)
please note I am trying to add this to a cakePHP query the code I currently have is below:
return $this->find('all', array(
'conditions' => $conditions,
'fields'=>array('SQL_CALC_FOUND_ROWS','Category.*','COUNT(`Entity`.`id`) as `entity_count`'),
'joins' => array('LEFT JOIN `entities` AS Entity ON `Entity`.`category_id` = `Category`.`id`'),
'group' => '`Category`.`id`',
'order' => $sort,
'limit'=>$params['limit'],
'offset'=>$params['start'],
'contain' => array('Domain' => array('fields' => array('title')))
));
Note the 'fields'=>array('SQL_CALC_FOUND_ROWS',' this obviously doesn't work as It tries to apply the SQL_CALC_FOUND_ROWS to the table e.g. SELECTCategory.SQL_CALC_FOUND_ROWS,
Is there anyway of doing this? Any help would be greatly appreciated, thanks.
Hi
In my mode I am selecting a field as
$query1 = $this->db->query("SELECT dPassword
FROM tbl_login
WHERE dEmailID='[email protected]'");
How to return dpassword as a variable to my controller
I tried this way return dpassword;
I've a typical scenario & need to understand best possible way to handle this, so here it goes -
I'm developing a solution that will retrieve data from a remote SOAP based web service & will then push this data to an Oracle database on network.
Also, this will be a scheduled task that will execute every 15 minutes.
I've event queues on remote service that contains the INSERT/UPDATE/DELETE operations that have been done since last retrieval, & once I retrieve the events for last 15 minutes, it again add events for next retrieval.
Now, its just pushing data to Oracle so all my interactions are INSERT & UPDATE statements.
There are around 60 tables on Oracle with some of them having 100+ columns. Moreover, for every 15 minutes cycle there would be around 60-70 Inserts, 100+ Updates & 10-20 Deletes.
This will be an executable jar file that will terminate after operation & will again start on next 15 minutes cycle.
So, I need to understand how should I handle WRITE operations (best practices) to improve performance for this application as whole ?
Current Test Code (on every cycle) -
Connects to remote service to get events.
Creates a connection with DB (single connection object).
Identifies the type of operation (INSERT/UPDATE/DELETE) & table on which it is done.
After above, calls the respective method based on type of operation & table.
Uses Preparedstatement with positional parameters, & retrieves each column value from remote service & assigns that to statement parameters.
Commits the statement & returns to get event class to process next event.
Above is repeated till all the retrieved events are processed after which program closes & then starts on next cycle & everything repeats again.
Thanks for help !
Hi everybody,
How do you use a php variable (array) inside a mysql select statement?
I am designing an auction site and currently working on a page that lets people view a list of all the current bids for an item. I want to display 3 columns:
amountbid - the amount each bidder has bid for the item (held in tblbid)
bidderid - the id of each bidder who has bid (found in tbluser)
total_positivity_feedback - how many users have left positive feedback for the bidder (calculated from tblfeedback)
To find the 'amount' and the 'bidderid' columns i pass the essayid URL parameter from the previous page. This works fine.
Despite this, i can't display the total_positivity_feedback column for the various users who have made each bid.
My mysql query looks like this:
select
tblbid.bidderid,
tblbid.amount,
(select count(tblfeedback.feedbackid) from tblfeedback WHERE tblfeedback.writerid = "ARRAY VARIABLE GOES HERE") AS total_positivity_feedback FROM tblbid WHERE tblbid.essayid = $essayid_bids
I assume that the only way to accomplish this is to make the variable contain the bidderid's of those people who bid for that particular essay? I can't seem to work out how to do this tho?!?
Many thanks for your help
Can we get a list of basic optimization techniques going (anything from modeling to querying, creating indexes, views to query optimization). It would be nice to have a list of these, one technique per answer. As a hobbyist I would find this to be very useful, thanks.
And for the sake of not being too vague, let's say we are using a maintstream DB such as MySQL or Oracle, and that the DB will contain 500,000-1m or so records across ~10 tables, some with foreign key contraints, all using the most typical storage engines (eg: InnoDB for MySQL). And of course, the basics such as PKs are defined as well as FK contraints.
I want to make a festival calendar using asp.net from that I used two ajax calendar and one textbox it is a festival textbox where we enter festival which FromDate and ToDate respectively. I want to do this as following point
If I enter in textbox Christmas and Choose Fromdate=25/12/2011 and ToDate=31/12/2011 then it will be valid
If I choose fromDate=25/12/2011 and ToDate=24/12/2011 then it will invalid
If I choose Fromdate=25/12/2011 and Todate=28/12/2011 then also it is invalid because it coming in between 25/12/2011 and 31/12/2011
If I Choose fromdate=1/1/2011 and ToDate=1/1/2011 then it is valid
If I choose fromdate=21/12/2011 and 25/12/2011 then it is invalid because of already Christmas done in 1/1/2011
And all date should show in gridview like 25-dec-2011 format
Here is my code:
DateTime dt1 = Convert.ToDateTime(txt_fromdate.Text);
DateTime dt2 = Convert.ToDateTime(txt_todate.Text);
if (dt1 > dt2)
{
con.Open();
com = new SqlCommand("BTNN_MovieDB_Festival_Details_Insert", con);
com.Parameters.Add("@fromdate", SqlDbType.VarChar).Value = dateformat_mmdd(txt_fromdate.Text.ToString().Trim());
com.Parameters.Add("@todate", SqlDbType.VarChar).Value = dateformat_mmdd(txt_todate.Text.ToString().Trim());
com.Parameters.Add("@return", SqlDbType.VarChar).Direction = ParameterDirection.ReturnValue;
com.ExecuteNonQuery();
con.Close();
showdata();
}
else if (dt1 < dt2)
{
lblerror.Text = "ToDate should be greater than FromDate";
}
Hi all,
I've decided to develop a database driven web app, but I'm not sure where to start. The end goal of the project is three-fold: 1) to learn new technologies and practices, 2) deliver an unsolicited demo to management that would show how information that the company stores as office documents spread across a cumbersome network folder structure can be consolidated and made easier to access and maintain and 3) show my co-workers how Test Drive Development and prototyping via class diagrams can be very useful and reduces future maintenance headaches.
I think this ends up being a basic CMS to which I have generated a set of features, see below.
1) Create a database to store the site structure (organized as a tree with a 'project group'-project structure).
2) Pull the site structure from the database and display as a tree using basic front end technologies.
3) Add administrator privileges/tools for modifying the site structure.
4) Auto create required sub pages* when an admin adds a new project.
4.1) There will be several sub pages under each project and the content for each sub page is different.
5) add user privileges for assigning read and write privileges to sub pages.
What I would like to do is use Test Driven Development and class diagramming as part of my process for developing this project. My problem; I'm not sure where to start. I have read on Unit Testing and UML, but never used them in practice. Also, having never worked with databases before, how to I incorporate these items into the models and test units?
Thank you all in advance for your expertise.