Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



SQL query to return unique output based two fields from one table

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 16-11-2009
Member
 
Join Date: Jan 2009
Posts: 45
SQL query to return unique output based two fields from one table

Hi Guys,

My problem is I want SQL query to return unique output based on fields from two tables.


I have a table tag_phto which is a join table and has two fields: tag_Id and Phto_Id.

I have to create a page which will have a list of all tags and a thumbnail against each tag in the table.But I only have to show each tag only once and a different photo for each tag.

Can you able to help me to solve this issue?..
Reply With Quote
  #2  
Old 16-11-2009
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
Re: SQL query to return unique output based two fields from one table

Hi ,

Have you tried below method ? if not then try it.This method will definitely give you the desired output:

Query:

select tag_Id, Min(Phto_Id)
from tags_phto
group by tag_Id
Reply With Quote
  #3  
Old 16-11-2009
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
Re: SQL query to return unique output based two fields from one table

The answer for your problem is very easy.I also wanted the similar type of output.
At that time I used DISTINCT.The DISTINCT avoids the duplication in the output.

Syntax:

SELECT DISTINCT field1, field2..... from table_name

Example:

SELECT DISTINCT tag_id, phto_id from tag_phto
Reply With Quote
  #4  
Old 16-11-2009
Member
 
Join Date: May 2008
Posts: 1,990
Re: SQL query to return unique output based two fields from one table

According to me this is because what you want is not achievable via SQL only. If I can understand your request correctly, what you are asking for is a page with the tag displays only once and all of the photos associated with that particular tag.

See below:

Tag PhtoTag
6 26
16
78


Your page will accept a Tag and independently get all of the phtoTag associated with that perticular tag .But SQL will give you a repeating value for Tag.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "SQL query to return unique output based two fields from one table"
Thread Thread Starter Forum Replies Last Post
PHP mysql select unique records from one table Captain Carrot Software Development 6 13-05-2010 01:18 PM
Select unique records from a table Conraad Software Development 5 13-05-2010 01:01 AM
Need list of fields of table in print Murder Windows Software 4 03-09-2009 06:17 PM
How to Create view based on table-join query Preetish Windows Software 3 12-08-2009 02:44 PM
Combination of Two fields in one SQL Query Andrzej Software Development 3 19-02-2009 11:58 AM


All times are GMT +5.5. The time now is 07:39 AM.