Hi,
How do i connect tables so they are interrelated to each other. like the asp.net 2.0 membership tables have the "id"
and how can i use that?
i have multiple tables that are all connected.
like i have a table for profile. and images
profile with include their profile, while images will include there avatar.
now when i display there profile on page, i need to grab the data from both the profile table and avatar.
right now i've been using the "JOIN" statement. but is tehre any other way
only join is made in sql for getting information from interrelated tables in database.
use inner/outer as per your requirement.
thanks
vishal sharma
|||Hello my friend,
The JOIN is the "de-facto" way of getting related data and saves you from having to do 2 or more separate queries. Some info on joins: -
FROM profile INNER JOIN images ... - if profile does not have an image or vice versa, no records will be returned.
FROM profile LEFT OUTER JOIN images - if profile exists but image does not, a record will be returned with the image fields as NULL. Profile record must exist.
FROM profile RIGHT OUTER JOIN images - if image exists but profile does not, a record will be returned with the profile fields as NULL. Image record must exist.
Kind regards
Scotty
|||
- Yeah, you can do a SubSelect if you are doing something simple like getting 1 value from 1 table instead of JOINing to that table.masfenix:
right now i've been using the "JOIN" statement. but is tehre any other way
Example:
SELECT
*,
(SELECT TOP 1 Blah FROM myOtherTable WHERE myOtherTable.UserID = myTable.UserID)
FROM
dbo.MyTable
so is what is it?
is it not join?
|||join is better option.
other thing you can do is
select tableA.field, tableB.field where tableA.Id = tableB.Id something like that.
thanks,
satish
|||You can see an example of when you would use JOINing or SubSelects of what I posted above can be found in this article :http://www.singingeels.com/Articles/How_To_Maintain_Customer_Payment_History.aspx
No comments:
Post a Comment