w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Execution of multiple select statements
The way to join two sets of results is to use UNION ALL ResultSet rs=s.executeQuery( "select attr_name,count(*) from Table_name group by attr_name UNION ALL select attr_name,count(*) from Table_name group by attr_name" ); Be careful to make sure that the columns are the same: there must be the same number of columns and they must be of the same type. It would also be worth explicitly naming the columns to make sure: SELECT attr_name, count(*) AS attr_count FROM...

Categories : Java

SQL JOIN vs. multiple SELECT statements
Why does the RDBMS driver don't solve this problem? For the same reason that the query optimizer also sometimes doesn't get it right. This is hard. The database (and other software) does its best to optimize query execution, but sometimes you still need to manually "help it". If anything, I'd prefer only the database itself to even try its hand here, and not have other layers (such as the OR/mapper or the database driver) also fiddle around "automagically". Otherwise the process would become completely unpredictable and hard to steer if necessary.

Categories : SQL

SQL: Linking Multiple Rows in Table Based on Data Chain in Select
SELECT * FROM LinkedTable lt WHERE ft.link_sequence IN ( SELECT link_sequence FROM LinkedTable WHERE code = 3245 AND link_sequence IS NOT NULL ) ORDER BY ft.ID; See my SQL Fiddle DEMO. SECOND ATTEMPT: SELECT DISTINCT * FROM LinkedTable START WITH code = 3245 CONNECT BY NOCYCLE PRIOR code = code AND PRIOR link_sequence+1 = link_sequence OR PRIOR code <> code AND PRIOR link_sequence = link_sequence ORDER BY link_sequence, code ; Updated SQL Fiddle with this code. Please try to break it. Based on your data (starting with 3245) it gives the following chain: ID CODE LINK_SEQUENCE NAME 2 3245 1 Potato 1 3267 1 Potato 3 3245 2 Potato 4 3975 2 Potato 5 3975 3

Categories : SQL

Inner join of multiple dynamic select statements
Try this one - DECLARE @Attributes NVARCHAR(2000) , @SQL NVARCHAR(MAX) SELECT @Attributes = '1@3@4@kaal#maal#saal,2@5@6@nn#mm' DECLARE @tblAttributes TABLE ( RowNum INT IDENTITY(1, 1) , Attribute NVARCHAR(1000) ) INSERT INTO @tblAttributes (Attribute) SELECT RTRIM(LTRIM(p.value('.', 'NVARCHAR(1000)'))) FROM ( SELECT field = CAST('<s>' + REPLACE(@Attributes, ',', '</s><s>') + '</s>' AS XML) ) d CROSS APPLY field.nodes('/s') t(p) DECLARE @Counter INT , @RowCount INT SELECT @RowCount = COUNT(RowNum) , @Counter = 1 FROM @tblAttributes WHILE @Counter <= @RowCount OR @Counter = 1 BEGIN DECLARE @AttributeID INT , @InputTypeID INT , @ValidationTypeID INT , @AttributeValue NVA

Categories : SQL

Multiple simultaneous SELECT statements in MySQL
You should use transaction. Not on client app, but on server app. begin transaction update table1 set .... update table2 set .... update table2 set .... commit this way, table1 and table2 committed simultaneously, ensuring consistent read on client apps. Note: you have to use InnoDB engine for transaction to work

Categories : C#

Using multiple SELECT statements to narrow results
Combining results of multiple SELECT statements means you need to use UNION. Please see this : http://dev.mysql.com/doc/refman/5.0/en/union.html (SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) UNION (SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);

Categories : PHP

Inner join vs select statements on multiple tables
The 2 SQL statements are equivalent. You can look at the execution plan to confirm. As a rule, given 2 SQL statements which affect/return the same rows in the same way, the server is free to execute them the same way.

Categories : Sql Server

Multiple select statements in one, creating new columns
Try this one - DDL: DECLARE @PositionData TABLE (PositionId INT, pdPosition INT) INSERT INTO @PositionData (PositionId, pdPosition) VALUES (1765, 1765),(1767, 1767), (1768, 1768) My query: SELECT [Region 1] = MIN(CASE WHEN PositionId = 1765 THEN pdPosition END) , [Region 2] = MIN(CASE WHEN PositionId = 1767 THEN pdPosition END) FROM @PositionData WHERE PositionId IN (1767, 1765) bummi query: SELECT (SELECT pdPosition FROM @PositionData WHERE PositionId = 1765) AS [Region 1] ,(SELECT pdPosition FROM @PositionData WHERE PositionId = 1767) AS [Region 2] Output: Region 1 Region 2 ----------- ----------- 1765 1767 (1 row(s) affected) Region 1 Region 2 ----------- ----------- 1765 1767 (1 row(s) affected) Query cost:

Categories : SQL

The right mySQL syntax for multiple SELECT statements?
The first query also wont work. try this. SELECT AVG(salaryoffered) AS "Average Salary", MIN(salaryoffered) AS "Min Salary", MAX(salaryoffered) AS "Max Salary" FROM interview; If you want to add some text, use concat, something like SELECT concat(AVG(salaryoffered), "$ offered") AS "Average Salary", concat(MIN(salaryoffered), "$ offered") AS "Min Salary", concat(MAX(salaryoffered), "$ offered") AS "Max Salary" FROM interview;

Categories : Mysql

Multiple select statements, not the same amount of columns
Try this : Declare @Topmost int=1234, @MinPositionId int SELECT @MinPositionId=min(pos.PositionId) FROM PositionData pos WHERE pos.pdOpsReportLine = @Topmost select @Topmost Topmost,@MinPositionId Reportline Union all SELECT '',pos.PositionId FROM PositionData pos WHERE pos.pdOpsReportLine = @Topmost and pos.PositionId != @MinPositionId

Categories : SQL

MySQL syntax issue, multiple SELECT statements
SELECT a.username, COUNT(b.by_user) totalCount, SUM(IFNULL(b.votes,0)) total_votes FROM users_fb a LEFT JOIN posts b ON a.id = b.by_user WHERE b.by_page = '0' GROUP BY a.id,a.username

Categories : Mysql

postgres multiple JDBC select statements in batch
You don't need to jump through any hoops for this. Just BEGIN a transaction in SERIALIZABLE isolation and the two statements will see a consistent view of the data. See the JDBC tutorial. There is no other way to ensure two statements see the same data. You could send them together, but unless they're wrapped in a transaction they could still see different data.

Categories : SQL

Use multiple EXEC statements depending on a SELECT result
within a query you are allowed to use functions but you are not allowed to use stored procedures. if you have to call a stored procedure you should use a cursor and loop through your results PL/SQL Cursors on Oracle.com BEGIN FOR c IN (SELECT * FROM tablename) LOOP your_procedure(c.columnname, c.othercolumnname); END LOOP; END;

Categories : SQL

Getting result of multiple SELECT statements from stored procedure
Union them together SELECT TOP 5 title,summary,cphoto,pId FROM [post] WHERE [status]=1 UNION ALL SELECT TOP 1 title,summary,cphoto,pId FROM [post] WHERE [status]=1 UNION ALL ... order by title DESC;

Categories : SQL

How to join multiple select statements in SQL and display in different colums
Union is not the correct approach. Union combines or merges to result sets with the same number of columns and data types. I would do something like this instead. SELECT ( SELECT COUNT(FilteredAppointment.createdbyname) FROM FilteredBusinessUnit INNER JOIN FilteredSystemUser ON FilteredBusinessUnit.businessunitid = FilteredSystemUser.businessunitid INNER JOIN FilteredAppointment ON FilteredSystemUser.systemuserid = FilteredAppointment.createdby WHERE (FilteredBusinessUnit.name IN (@Branch)) ) AS Appointment , ( SELECT COUNT(FilteredLead.fullname) FROM FilteredBusinessUnit INNER JOIN FilteredSystemUser ON FilteredBusinessUnit.businessunitid = FilteredSystemUser.businessunitid INNER JOIN Fil

Categories : SQL

select multiple rows in gridview without checkbox
We can take a hidden field inside a gridview and on click of girdview row, means on selected index event, find the hidden field in selected row we can make it as 1 . now with loop of each row we can find the rows having hidden field value as 1 thats the way i think we can achieve, in case of select and de select we can toggle the value of hidden field

Categories : C#

LINQ Query Using Navigation Properties Generates Multiple SELECT Statements
As said in the comment you need the Include method: SalesOrderHeaders.Include(s => s.SalesOrderDetails .Select(d => d.SpecialOfferProduct)) .Where(s => s.SalesOrderID == 43659) .Single().SalesOrderDetails this will join the required data (in SQL) and populate the navigation properties. Note, however, that you can't use syntax like .Include(s => s.SalesOrderDetails.Where(sod => sod.OrderQty > 3) .Select(d => d.SpecialOfferProduct)) Which seemingly would partly populate SalesOrderDetails. There are change requests to the EF team to implement this, but so far, this hasn't been done. Another side note is that it's useless to return SpecialProducts as IQueryable because subsequent queri

Categories : C#

Do MySQL transactional queries improve performance for multiple SELECT statements?
Transactions can give big boost for INSERT/UPDATE/DELETE queries (provided that you use transactional engine like InnoDB), but on SELECT only queries, using transactions are NOT likely to improve performance (but may be still needed by your application logic to ensure consistency). Main reason for speed difference: if you do not use transactions, server must flush every single update to disk as soon as possible, to make sure that data will survive should server crash or lose power. With transactions, server only needs to guarantee that all updates batched in one transactions are committed to disk, or the whole thing is rolled back. In other words, server is free to group many writes into few disk operations, and only needs to commit transaction when it is absolutely sure that data is safe

Categories : PHP

Are multiple-table DELETE statements bad practice? Why?
One possible problem that I could see is that if it there is a glitch (like a server breakdown, power outage etc) and you already deleted the parent records (from the parent table) before the related child record(s) then you have what is known as orphan record(s) meaning the related child record/table could no longer be related to a mother record/table. Although this could overcome if you delete first the child table/record before the parent table/record. Another one is performance issue since MyISAM uses table-level locking so deleting multiple records (from multiple tables) has bigger chance of degrading the access time performance than say deleting from few sources.

Categories : Mysql

Postgres Create Table As Select query with multiple left outer joins produces duplicated data
There're should be a duplicate udid in one of your tables - if you have no unique constraint on udid, check result of select udid from ... group by udid having count(*) > 1 on your tables to find out

Categories : SQL

select all of table A left join column of table B with multiple wheres that dont affect showing all of table A
I think you just need to move the condition on the work_orders_billing_codes table into the on clause. Then if there is no match, you will still get all the appropraite records in billing_codes. SELECT bc.`id` AS `id`, bc.`billing_code` AS `billing_code`, bc.`desc` AS `desc`, bc.`point_value` AS `point_value`, wobc.`quantity` AS `quantity`, wobc.`billing_code_id` AS `id2` FROM `cl_billing_codes` bc LEFT JOIN `cl_work_orders_billing_codes` wobc ON bc.id = wobc.`billing_code_id` AND wobc.`work_order_id` = 1585 WHERE bc.`service` = '1' ORDER BY `billing_code`;

Categories : PHP

conditional statements in data.table
You are assigning values to variables "inside" the if/else-statement. Try this: dt1=dt[,list( nbet=nchar(bet), riskybet = if (nchar(bet)>2.5) 1 else 0, win = if (grepl(outcome, bet)) 1 else 0), by='id,trial'] id trial nbet riskybet win 1: 11 1 1 0 0 2: 11 2 3 1 0 3: 11 3 4 1 1 4: 11 4 3 1 1 5: 12 1 2 0 0 6: 12 2 4 1 0 7: 12 3 2 0 0 8: 12 4 3 1 1 Alternatively you could also use ifelse instead of the traditional if-else.

Categories : R

Word Search Game: How to Select Multiple Items in a GridView By Dragging? (Android)
I'm late to this question but coming across a similar problem recently, I decided to create my own custom board view library to address this problem. It adds more flexibility to what you can do and it leads to a more straightforward implementation. Here are some snippets of code showing how it works. First, it is easy to draw the board grid on a custom view's onDraw() method: @Override protected void onDraw(Canvas canvas) { for (int i = 0; i <= numRows; i++) { //For custom grid sizes, y can't be equal the board size or the line drawn won't show int y = Math.min(boardHeight - 1, i * tileSize); canvas.drawLine(0, y, boardWidth, y, boardPaint); } for (int i = 0; i <= numCols; i++) { //For custom grid sizes, x can't be equal the board size o

Categories : Android

How to display the multiple rows of images in gridview from sql table
Your handler, though running through a loop, will only return the first image it comes across. By calling these lines....: context.Response.BinaryWrite((Byte[])dtst.Rows[i]["image"]); context.Response.ContentType = "image/jpeg"; context.Response.End(); .....your essentially saying "Ok, you can stop now and spit out that image" - your other images in the loop won't be reached. Your handler should really only return a SINGLE image. So change your handler so it delivers just ONE image, you can put the ID of the image you want to display in the querystring, and then call the handler from your gridview. Something like (example, not tested) <asp:TemplateField HeaderText="MyImage"> <ItemTemplate> <asp:Image runat="server" ImageURL='<%# Ev

Categories : C#

When Binding Data from a Service GET call to Gridview, cant select only certain columns
Without seeing your GridVew declaration in markup, since you are seeing all of the columns from the query, then I am saying your AutoGenerateColumns property is set to true, like this: <asp:GridView AutoGenerateColumns="True"... If you wish to not have all columns automatically returned, then you need to set this property to false, like this: <asp:GridView AutoGenerateColumns="True"... Now, since you have said to not have the data decide on what columns get rendered, you need to tell the GridView what columns you want via the Columns markup. Read MSDN Documentation for GridView.Columns Property

Categories : C#

How to load Data from a second table in GridView
Try using join and select the user name too for your object data source and use the user name to display it instead of user id. Refer this link How to do a join in linq to sql with method syntax?

Categories : Asp Net

Select data from one table and insert into another existing table, which doesn't exist in the table
I think you are looking for this INSERT INTO table4( id1, id3) SELECT id1, id3 FROM table2 INNER JOIN table1 ON table1.id2 = table2.id2 Left JOIN table3 ON table2.name2 = table3.name3 WHERE name2 LIKE 'input' and table3.name3 is null or something similar. Left (outer join) gets all the records in table2 whether they exist or not. If they don't table3.name3 will be null, so those are the chaps you want.

Categories : Mysql

Delete data in sql table using c# and present it in gridview
The problem is that probably no empID with the value 'empID' exists.. You didn't put the value of the empID in the command, but added an exact string of 'empID', which cannot be found in your table. Put the empID value as a parameter like Icarus advised.

Categories : C#

Select data from table B where a field in table B matches table A (php mySQL)
Assuming table_a is the name of the livestock table and table_b is the table with the description in it, you'll want to join the tables on the 'scientific' field. SELECT table_a.*, table_b.Description FROM table_a JOIN table_b ON table_a.Scientific = table_b.Scientific You'll want to replace table_a and table_b with the correct table names.

Categories : PHP

Bind gridview using jquery : Have table data clickable
You are closing the anchor element in your code twice... <a href="#" onclick="getStock()" value=' + codes + ' />' + codes + '</a> Should be: <a href="#" onclick="getStock()" value=' + codes + '>' + codes + '</a> (note the removed "/" right before the anchor's greater-than character)

Categories : Javascript

Inserting data into gridView without using SqlDataSource and DataBind from a Sql Table
I would just include the extra column in your select statement and just bind to the gridview - unless there's a specific reason for not doing that. note the new sql! public void GetRowHeaders(GridView gridViewSample) { string commandstr = @"SELECT a.*, b.somecolumn FROM tablea as a inner join tableb as b on b.someid= a.someid WHERE ID!=0 ORDER BY ID"; SqlCommand rowHeaderCmd = new SqlCommand(commandstr, sqlcon); sqlcon.Open(); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = rowHeaderCmd; da.Fill(dt); gridViewSample.DataSource = dt; gridviewSample.DataBind(); sqlcon.Close(); } Or you could populate a collection of some class ( remember to use properties for gridviews databind), a List maybe, and jus

Categories : C#

Multiple If-Else Statements VS. Switch Statements within While Loop for C Language
No, that code is not possible to write with a switch. The values for case must be constant, and integer. You can have case 4611: but not `case a > 360". So, unless you want hundreds of case statements (you don't) the code is not easily translatable to use a switch. UPDATE One way to make it (in my opinion) more elegant is to order the ranges, and reduce repeat by relying on the lower bound already having been checked in all else ifs: while(1) { const float A = get_angle(); if (A > 1 && A <= 180) { put_speed (600, 200); } else if (A <= 360) { put_speed(600, 100); } else if (A <= 540) { put_speed(100, 600); } else if (A <= 700) { put_speed(200, 600); } else {

Categories : C

How can I handle different data types in an Entity-Attribute-Value design (e.g. single table with multiple columns or multiple tables per data type)?
This is a well known problem. The problem with the approach you mentioned is that you need to know the type of the attribute before you query for it. it's not the end of the world because you manage metadata but still... Two possiable solutions might be using a varchar2 datatype to represent all data types in a known format. Numbers and chars are no problem, date values can be written in a predefined manner (it's like implementing to_String() in any OO design). use the ANYDATA data type. i personally played around with it but decided not to use it.

Categories : Database

Insert strings from data table to gridview and show them as links
You looking for HyperLinkField in gridview <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false"> <Columns> <asp:hyperlinkfield datatextfield="Name" datanavigateurlfields="Url" datanavigateurlformatstring="{0}" headertext="Url" target="_blank" /> </Columns> </asp:GridView>

Categories : C#

Javascript show multiple table rows from multiple select
I have fixed the problem myself, the solution was: $('table#newspaper-a tr:not(#header, #trWeekNummer)').hide(); if(List[x].selected) { $('table#newspaper-a tr:not(#header, #trWeekNummer)').each(function(){ $('td:nth-child(1)',this).each(function(){ if($(this).text() == List[x].value) $(this).parent(this).show(); }); }); }

Categories : Javascript

Unable to export multiple pages of gridview data to excel
This may help. It reiterates all columns and rows and export to Excel sheet.You need to add Microsoft.Office.Interop.Excel private void button2_Click(object sender, EventArgs e) { // creating Excel Application Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application(); // creating new WorkBook within Excel application Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); // creating new Excelsheet in workbook Microsoft.Office.Interop.Excel._Worksheet worksheet = null; // see the excel sheet behind the program app.Visible = true; // get the reference of first sheet. By default its name is Sheet1. // store its reference to worksheet

Categories : C#

Gridview returning empty even when there is data. I want to use data in the gridview to update another database
Per my comment above you may want to do something like: List<string> _OrderIds = new List<string>(); DataTable table = gvOrderLines.DataSource as DataTable; foreach (GridViewRow gvr in table.Rows) { Label myOrderIDLablel = (Label)gvr.FindControl("lblOrderID"); //find control since it is a template field _OrderIds.Add(myOrderIDLablel.Text); } I hope this get you headed in the right direction.

Categories : C#

display gridview data in another page or other gridview with row data in editable mode
You need to add RowCommand Event in GridView. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"> <asp:LinkButton ID ="lnkEdit" runat ="server" CommandArgument='<%#Eval("Recordid")%>' CommandName ="cmdEdit" Text ='Edit'></asp:LinkButton> </asp:GridView> Here rocordid is the id of your record. In Page behind you need to write code. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "cmdEdit") { string Recordid = Convert.ToString(e.CommandArgument.ToString()); Response.Redirect("EditPage.aspx?recordid="+Recordid ); } } On EditPage you can get recordid from the query string and can fetch the record form the datab

Categories : Asp Net

I need to select data from a table according to time.But my table field is datetime
Try this one - DECLARE @temp TABLE ( Col1 INT , Col2 DATETIME ) INSERT INTO @temp (Col1, Col2) VALUES (1, '2013-08-29 07:41:43.717'), (2, '2013-08-29 08:41:50.067') SELECT * FROM @temp WHERE CAST(Col2 AS TIME) BETWEEN '08:00' AND '12:00' Output - Col1 Col2 ----------- ----------------------- 2 2013-08-29 08:41:50.067

Categories : Sql Server

select data from one table, check against and pull values from second table
From looking at your code, I am assuming the actions.action_int field correlates to the questions.id field, and I believe this is what you're asking for: SELECT actions.action_id, actions.action_type, actions.action_details, actions.action_int, actions.action_time, questions.section_id FROM actions JOIN questions ON actions.action_int = questions.id WHERE user_id = '".$id."' AND action_type = 'other' AND ( action_details = 'random question' OR action_details = 'review') AND action_int IN ( SELECT id FROM questions WHERE section_id IN (2,3,4,5,6,7,8) )

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.