473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

check all data from a SQL table dependent upon another two tables

I have three table in database for a simple blog.

1st(userdata) is for userID userName, profession, birthdate & other personal information.

2nd(postdata) is for postID, userID postBody, postTitle, postDate

3rd(commentdata)is for commentID, postID, commentBody.

now I want to bind these data in a asp.net datalist so that for TOP 10 post userName, postTitle, postBody and number of comments for each post is shown. How can design the sql command. I tried

SELECT TOP 10 userdata.name, postid, postdata.uid, postdata.title, postdata.body, postdata.postdate"
+ " FROM postdata INNER JOIN userdata ON postdata.uid = userdata.uid ORDER BY postdata.postdate DESC

Now how can I attach "postdata" table with this command
to get COUNT(postid)
Feb 12 '11 #1
1 2026
nathj
938 Expert 512MB
Hi,

I would try something like:

SELECT
a.name, b.postid, b..uid, b.title, b.body, b.postdate FROM postdata b
LEFT JOIN userdata a ON b.uid = a.uid
ORDER BY b.postdate DESC
WHERE row >= 1 AND row <= 10

That SQL should sort you out. It's a shame SQL Server hasn't implemented LIMIT like in MySQL

Cheers
nathj
Feb 12 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
5
by: Shibu | last post by:
Hi, I have a situation where I need to convert business objects to a flat table. The reverse is also required. I am using c# and Oracle ODP. I am looking for an easier method to do the below...
2
by: Brian Mitchell | last post by:
Ok, I know this is an elementary question but I have a data grid that is bound to a data table and I can't seem to find a way to match the selected row in the grid with it's respective row in the...
11
by: Ron L | last post by:
I have a data table that lists a series of items in my database. In my user form, I want the user to be able to filter by a number of criteria (e.g. location, contract, date modified, etc). Other...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
1
by: new214 | last post by:
Hey all, got abit of a problem. Ive got a database where ive got 2 tables. I want to create a command which selects * from table 1 and if the same values are in table2 - it updates otherwise adds. ...
1
by: Dan2kx | last post by:
Hello, me again i am creating tables (and deleting them) based on the Public variable StaffID the reason for this is the information used in these tables is used to display staffing information...
0
parshupooja
by: parshupooja | last post by:
Hey All, I am trying to create utility to check data inconsistency in ASP.net 2.0 C# means I want to compare two databases in two different sources i.e MS Access and SQL Server. I want to...
15
by: Peter | last post by:
I have the following web page and I am trying to have the Field lables NOT to wrap. It looks fine in a designer but when I run the program in a browser the lables that have a space wrap. How do I...
3
by: southpawjoe | last post by:
Hi, I would like to insert data into two related tables in a SQL Server 2008 database. I created the following stored procedure but it has a problem. When I add a record, the State table gets...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.