Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
This is the output of joining 2 tables by inner join.
I want linq query of joing two table as inner join and group by name from one table and sum of total from another table column as taken snapshot as above.pls help
Check this post.
var result = (from a in ctx.TableA
join b in ctx.TableB on a.Id equals b.Id
group a by a.Name into g
select new
{
Name = g.Key,
Sum = g.Sum(i => i.Total)
}).ToList();
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Create an index-by table and populate with rows from emp, then loop over and print them.
hi can anyone understand this question and give me the suggestions to solve this please..
A collection is an ordered group of elements having the same data type
which can be accessed though subscript/index. Oracle PL/SQL supports
three different types of collection
Index-by tables or Associative array
Nested table
Variable-size array or Varray
Below is an example of how you can define a Index-by table and populate it with rows from Emp table and print them accordingly.
DECLARE
CURSOR c_emp is
select name from emp;
TYPE c_list IS TABLE of emp.name%type INDEX BY binary_integer;
name_list c_list;
counter integer :=0;
BEGIN
FOR n IN c_emp LOOP
counter := counter +1;
name_list(counter) := n.name;
dbms_output.put_line('Employee('||counter|| '):'||name_list(counter));
END LOOP;
END;
/
See Oracle Documentation as well as PL/SQL - Collections for more information on the same.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to update details using linq to entities. But instead of takin a new aspx page i want to update details in another view. will it work.? and please give the linq to entity update query
Let us assume:
db is the context of your Database Entity.
Table_name is the name of Table you need to update.
row_id is the value you are using to search for the data in the Table.
To update using linq you need to fetch the record first using the below query:
var data = (from r in db.Table_name
where r.id == row_id
select r).FirstOrDefault();
Now to update the values just update them. For example:
data.Name = "Firstname lastname"
data.IsActive = true;
.
.
and so on
After you have updated the values in data you need to Save the changes made by you by this command:
db.SaveChanges();
That's it.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have a table with Photos, allowing multiple rows per AlbumID:
Photos (photoID, photo,caption,albumID).
Albums (albumID,albumTitle)
I want a list of albumTitle and one photo for that albumID.
There are multiple photos in Photos table for a single albumID.
Can you provide a sql statement to select only one Photo per album id?
Thanks in advance!
Avi
SELECT AlbumID, MIN(PhotoID)
FROM PHOTOS
GROUP BY AlbumID
this will return only 1 of each instance of each albumID and a photo
SELECT DISTINCT `albumID `, `photo` FROM `Photos`;
and then you can:
SELECT
DISTINCT `albumID `, `photo`
FROM
`Photos`
INNER JOIN
`Albums`
ON `Albums.albumID` = `Photos.albumID`
AND `Albums.albumTitle` = `albumTitle`
Here's one way to do it using the Max(photoId):
Select a.albumId, a.albumTitle, p.photoId, p.photo, p.caption
From Albums a
Inner Join Photos p On a.albumId = p.albumId
Inner Join (
Select Max(photoId) maxPhotoId, albumId
From Photos
Group By albumId
) t On p.photoId = t.maxPhotoId And a.albumId = t.albumId
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In my database I have 3 tables, one for customers, one for orders and one for products. A customer can have any number of orders and an order can have any number of products. How can I implement this relationship between the 3 tables?
Information stored in the database:
Customer: social security number, name, address, phone number
Order: order number, date
Product: product id, category, price
Ok Here's where to start.
First you need an ID for each table (an ID is a unique identifier, so that if i say want customer X, there won't be 2 customer X in the table)
For customer u can use social security number (or you create a column called CUSTOMER_ID)
A customer can have any number of orders, So you should put a column in order to know this order belongs to which customer. So in order you add a column called CUSTOMER_ID that references CUSTOMER_ID in the table CUSTOMER
so these 2 orders belong to CUSTOMER with CUSTOMER_ID = 1:
ORDER_NUMBER DATE CUSTOMER_ID
1 1/1/2013 1
2 2/1/2013 1
CUSTOMER_ID in ORDERS is called a FOREIGN KEY
The same goes for the rest.
(PS : change the name of the table ORDER, ORDER is a keyword used in SQL, to order the items SELECT .... FROM TABLE1 ORDER BY ....)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Get the last record from a Microsoft SQL database table using ASP.net (VB) onto a web form.
I'm assuming he's trying to retrieve the last inserted record. As Ariel pointed out, the question is rather ambiguous.
SELECT TOP 1 * FROM Table ORDER BY ID DESC
If you have an identity column called ID, this is easiest. If you don't have an identity PK column for example a GUID you wont be able to do this.
Here is a basic solution:
var order = (from i in db.orders
where i.costumer_id.ToString() == Session["costumer_id"]
orderby i.order_id descending
select i).Take(1).SingleOrDefault();
You need to be more specific with actually putting it onto a web form, but the SQL to get the last record is:
SELECT *
FROM TABLE_NAME
WHERE ID = (SELECT MAX(ID) FROM TABLE_NAME)
Where ID is your ID and TABLE_NAME is your table name.