473,847 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select distinct on two tables

I have two tables, both containing an 'authors' column. Is there a way
to get a unique list of authors from the two tables?
I tried SELECT DISTINCT `authors` from `table1`, `table2`;
but I got an "Column 'authors' in field list is ambiguous" error.

Is there also a query to return only the count of distinct authors from
the two tables?

Thanks for any help.

Jul 23 '05 #1
2 12552
mf*****@gmail.c om wrote:
I have two tables, both containing an 'authors' column. Is there a way
to get a unique list of authors from the two tables?
I tried SELECT DISTINCT `authors` from `table1`, `table2`;
but I got an "Column 'authors' in field list is ambiguous" error.
Try this:
(SELECT `authors` FROM `table1`)
(SELECT `authors` FROM `table2`)
ORDER BY `authors`

See http://dev.mysql.com/doc/mysql/en/union.html for more information.
Is there also a query to return only the count of distinct authors from
the two tables?

For aggregates over multiple tables, I think you'd have to start using
MERGE tables, but this can be used only if the tables have identical

Another method would be to use a TEMPORARY table:
CREATE TEMPORARY TABLE authorlist (`authors` VARCHAR(100));
INSERT INTO authorlist SELECT DISTINCT `authors` FROM `table1`;
INSERT INTO authorlist SELECT DISTINCT `authors` FROM `table2`;
SELECT DISTINCT `authors` FROM `authorlist`;
SELECT COUNT(DISTINCT `authors`) FROM `authorlist`;

Bill K.
Jul 23 '05 #2
Thanks very much !

Jul 23 '05 #3

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

Similar topics

by: Marco Alting | last post by:
Hi I have two table which are related: table1 holds personellinformation table2 holds nodeInformation The nodes in table2 can have a nodeOwner which will then get a recordID from table1. A person can own multiple nodes.
by: BobG | last post by:
-- The issue This following query works fine on Toad and PowerBuilder yet when it is run on SQLPlus I get: "ORA-03113: end-of-file on communication channel" When I remove the distinct from the first line (capitalized below) it runs fine on SQLPlus. Is there some flag I need to set in SQLPlus to get this to work properly?
by: Craig Hoskin | last post by:
Hi everyone Have a problem I would areally appreciate help with. I have 3 tables in a standard format for a Bookshop, eg Products Categories Categories_Products the latter allowing me to have products in multiple categories.
by: Reestit Mutton | last post by:
Hi, I'm currently learning the ropes with CSS, PHP, MYSQL, Javascript etc... by redesigning my website as a database driven site. Okay, so I'm skilled at perl, data manipulation and data analysis and I've done a fair bit of (non CSS) HTML in the past and know what a relational database is. However, I'm having problems trying to formulate a particular MYSQL query (maybe I just don't know the lingo or maybe I've designed my data...
by: anmar | last post by:
I'm trying to figure out how to select all the records in one table which have multiple specified records in a second table. Here's a simplified version of my problem. I have two tables, resources and goals. resources table: ID TITLE
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT? These two attempts failed DataRow dr = ds.Tables.Select( "COUNT(DISTINCT(site_name))" ); object x = ds.Tables.Compute( "COUNT(DISTINCT(site_name))", "ProductionCount > 0" );
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement this function using select-for-update (or equivalent) in order to get a row-level lock (and thus less contention) while maintaining the function interface? The docs seem to suggest so, but it's not clear how to return the SETOF queued_item and also...
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an "interface" in Access. It's like a little system to make a production plan. It must get information about part numbers, description, set where the part number belongs, quantity of part numbers that the set uses, stock number(this is a text value, it...
by: CindySue | last post by:
Hello, I'm so stuck and this seems like it should be so simple. I have three tables, called Auction Items, Party #1 and Party #2. A bidder number may appear in one, two or all three of them. I'm trying to write a query that will select distinct bidder numbers that appear in one (or more) of the tables. I've found several pieces of code and tried to alter them, to no avail. The Winning Bidder Number field is the only thing I need from...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 most users, this new feature is actually very convenient. If you want to control the update process,...
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.