|
| |||||||||
| Tags: one table, query, return unique output, sql, sql query |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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?.. |
|
#2
| ||||
| ||||
| 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 |
|
#3
| ||||
| ||||
| 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 |
|
#4
| |||
| |||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |