954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Information from 2 tables via common column

I’m having some trouble and can’t seem to find the solution. Hopefully someone here can help me out.

I have two tables in a SQL Database and I’m trying to select some information from both tables where the column‘UniqueID’ has the same value.


Here is the information I require from the Tables:

Table Name:
Featured

Column Names:
UniqueID (value for both tables)
Approve
Date_Activation

Table Name:
Information

Column Names:
UniqueID (value for both tables)
Headline
Description
Ref_No
Rowguid

I found some information that said I could create a WHERE statement like the following:

where Table1.ColumnName = Table2.ColumnmName

I have tried this and it’s not working. Here’s my code:

select 
UniqueID as UniqueID,
Headline as Headline,
Description as Description, 

case when Approve = '1' then 'True' when Approve is null then 'False' else 'False' end as Approve,
Ref_No as RefNo,
Rowguid

from Featured, Information
Where Featured.UniqueID = Information.UniqueID
order by Date_Activation asc


Any help with this would be greatly appreciated.

abathurst
Light Poster
35 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

Try this one:

select
a.UniqueID,a.Headline,a.Description,b.Date_Activation,
case when b.Approve = '1' then 'True' when b.Approve is null then 'False' else 'False' end as Approve,
a.Ref_No as RefNo,
a.Rowguid

from Featured b inner join Information a
on a.UniqueID = b.UniqueID
order by b.Date_Activation asc

sufyan2011
Junior Poster
166 posts since Dec 2011
Reputation Points: 9
Solved Threads: 20
 

select featured.id,.........
from featured,information
where featured.id = information.id

vimit
Newbie Poster
11 posts since Jan 2012
Reputation Points: 10
Solved Threads: 2
 

Thanks sufyan,

that's working greate!

abathurst
Light Poster
35 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: