473,566 Members | 3,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Howto put these two queries together?

Howto put these two queries together?

sql = "SELECT DISTINCT medium_id, COUNT(tag) AS count FROM tags WHERE
tag = 'test' GROUP BY medium_id ORDER BY count DESC"

This query is working.

Id like to try something like

sql = "SELECT * FROM media WHERE id IN (SELECT DISTINCT medium_id FROM
tags WHERE tag = 'test')"

But how can I order the resut by quantity (counts of tag)?

Thank you for help.
//BEN

May 25 '06 #1
1 2332
Benny Schudel wrote:
Howto put these two queries together?
sql = "SELECT DISTINCT medium_id, COUNT(tag) AS count FROM tags WHERE
tag = 'test' GROUP BY medium_id ORDER BY count DESC"
sql = "SELECT * FROM media WHERE id IN (SELECT DISTINCT medium_id FROM
tags WHERE tag = 'test')"


SELECT m.*, COUNT(*) AS count
FROM media AS m JOIN tags AS t ON m.id = t.medium_id AND t.tag = 'test'
GROUP BY m.id
ORDER BY count DESC

Assuming m.id is a unique key for the media table.

Regards,
Bill K.
May 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
15227
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental differences between a view and a query, or rather, when it is more appropriate to use one vs. the other. It seems to me that most select queries can be...
9
4337
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user...
2
1392
by: nsh | last post by:
running access 2k; I have some stats (bowling) that I want to print in columns on a report. The top portion of the report will have a team-members name, and the bottom of the report will have a sub-report that presents the stats in UP-TO 4 columns.
0
1485
by: Mark Harrison | last post by:
HOWTO: Integrating Posgresql queries into an event loop. Mark Harrison mh@pixar.com May 27, 2004 Problem ------- The commonly used postgresql APIs will block until completed.
5
5544
by: listerofsmeg01 | last post by:
Hi, Pretty new to PHP and MySQL. I have a page on my site that displays a lot of information from various tables. Currently I have lots of small PHP wrapper functions around SQL queries to get each bit of information. This results in maybe 10 queries to display one page, but they are all very small and simple, and it keeps the PHP...
7
20304
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables, if they do not already exist. In terms of ASP/ADO, that would be fine in a SQL Server Sense by a simply ASP/Server-Side JavaScript as such: var...
2
2084
by: garethfx | last post by:
Hi all Anybody had experience bring together 2 or more crosstab queries using the UNION? ALL 3 crosstabs come from 3 sourcing queries from the same table so of course normally runnning 3 crosstabs at the sametime throws an error I have to pull 3 crosstabs together. All are laid out as The first is those number of people starting a...
7
5081
by: dmitrey | last post by:
hi all, can anyone explain howto get function from module, known by string names? I.e. something like def myfunc(module_string1, func_string2, *args): eval('from ' + module_string1 + 'import ' + func_string2') return func_string2(*args) or, if it's impossible, suppose I have some modules
1
4416
by: JosAH | last post by:
Greetings, Introduction This week we start building Query objects. A query can retrieve portions of text from a Library. I don't want users to build queries by themselves, because users make mistakes. Instead, the Library hands out queries to the user given a simple query String. This is how the library does it:
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.