Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
![]() |
•
•
Join Date: Sep 2007
Posts: 1,075
Reputation:
Rep Power: 4
Solved Threads: 62
hi, I have only done basic sql queries and need help on this major one trying to combine many queries into one.
What I need is to make the following queries into one:
Obviously I need to Combine these and I can do most of it myself, but not into one query. One to two queries would be okay. What I have so far is below, and I will update as I go. But I do need help on this if anyone can.
Now I am still missing these, which information for them is pulled with the above query:
SELECT PostUserName FROM ProfileComments WHERE PostUserID=..
SELECT MainPic FROM ProfileFriends WHERE FriendID=..
Oh, also so you should know, this is on MySQL v 5.0 or higher, and is being done in ASP.NET where I am binding them to repeaters. So it might not be the best solution. But I can work that out after I get the query
Thank you all!
What I need is to make the following queries into one:
SELECT Username, LastLogin, DateCreated, Views, MainPic, Logged FROM Users WHERE UserID=? SELECT COUNT(AlbumID) FROM ProfileAlbums WHERE UserID=? SELECT AlbumID FROM ProfileAlbums WHERE UserID=? LIMIT 4 SELECT COUNT(FriendID) FROM ProfileFriends WHERE UserID=? SELECT FriendUserID FROM ProfileFriends WHERE UserID=? LIMIT 12 SELECT MainPic FROM Users WHERE FriendUserID=? (comes from above statement) SELECT COUNT(CommentID) AS CommentsCount FROM ProfileComments WHERE ReceiveUserID=? SELECT PostUserID, DateCreated, Comment FROM ProfileComments WHERE CommentID=? LIMIT 25(comes from above statement) SELECT UserName, MainPic FROM Users WHERE UserID=PostUserID LIMIT 25 (comes from above statement)
"SELECT Users.UserName, Users.LastLogin, Users.DateCreated, Users.Views, ProfileAlbums.AlbumID, ProfileFriends.FriendID, Users.MainPic, Users.Logged, (SELECT COUNT(AlbumID) FROM ProfileAlbums WHERE UserID=?) As TotalAlbums, (SELECT COUNT(FriendID) FROM ProfileFriends WHERE UserID=?) As CountFriends, (SELECT COUNT(CommentID) FROM ProfileComments WHERE ReceiveUserID=?) As CommentsCount FROM Users INNER JOIN ProfileAlbums ON ProfileAlbums.UserID=? INNER JOIN ProfileFriends ON ProfileFriends.UserID=? INNER JOIN ProfileComments ON ProfileComments.PostUserID=? WHERE UserID=?"
SELECT PostUserName FROM ProfileComments WHERE PostUserID=..
SELECT MainPic FROM ProfileFriends WHERE FriendID=..
Oh, also so you should know, this is on MySQL v 5.0 or higher, and is being done in ASP.NET where I am binding them to repeaters. So it might not be the best solution. But I can work that out after I get the query
Thank you all! Last edited by SheSaidImaPregy : Nov 7th, 2007 at 2:03 pm.
•
•
Join Date: Sep 2007
Posts: 1,075
Reputation:
Rep Power: 4
Solved Threads: 62
This is what I have so far, all for asp.net:
I am not sure if it is possible to grab 4 queries with different limit sizes, not to mention if it is smart to bind 4 controls with tons of information rather than take the query hits. It's a profile section, much like myspace's. All by client's request.
repeater1: "SELECT UserName, LastLogin, DateCreated, Views, Logged, (SELECT COUNT(AlbumID) FROM ProfileAlbums WHERE UserID=?) As TotalAlbums, (SELECT COUNT(FriendID) FROM ProfileFriends WHERE UserID=?) As CountFriends, (SELECT COUNT(CommentID) FROM ProfileComments WHERE ReceiveUserID=?) As CommentsCount FROM Users WHERE UserID=? LIMIT 1" repeater2: "SELECT AlbumID FROM ProfileAlbums WHERE UserID=? LIMIT 4" repeater3: "SELECT MainPic As FriendMainPic FROM Users WHERE UserID IN (SELECT FriendID FROM ProfileFriends WHERE UserID=?) LIMIT 12" repeater4: "SELECT ProfileComments.PostUserID, ProfileComments.DateCreated, ProfileComments.Comment, Users.UserName As PostUserName, Users.MainPic FROM ProfileComments INNER JOIN Users ON Users.UserID=ProfileComments.PostUserID WHERE ProfileComments.ReceiveUserID=? LIMIT 25"
I am not sure if it is possible to grab 4 queries with different limit sizes, not to mention if it is smart to bind 4 controls with tons of information rather than take the query hits. It's a profile section, much like myspace's. All by client's request.
![]() |
Similar Threads
Other Threads in the ASP.NET Forum
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Need Freelance ASP.NET, MS SQL, C#, VB.NET Developer (Web Development Job Offers)
- Senior C#.Net Software Engineer - Oxfordshire - ASP. Net / SQL Server (Web Development Job Offers)
- Problem with Provider Management in ASP.NET 2.0 (ASP.NET)
- Asp.net Sql Query (ASP.NET)
- ASP .NET C# SQL on Visual Studio 2003, help? (ASP)
- Cheap ColdFusion/ASP.net 2/SQL 2005 Shared and Reseller Hosting (Web Hosting Deals)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: datagrid, innertext, javascript, database update
- Next Thread: displaying image from db
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode