...last name, quantities? I'm trying to compare two tables(or more...) from a database, and give a grand total of quantities if similar names are found. So far I have these two queries that work perfect(seemingly) alone, but I cannot seem to merge them successfully. Below are the commands as well as a summary of what the fields are:
ID INT(10) PRI NULL Auto_Increment
firstname, varchar(50)
lastname, varchar(100)
position, varchar(20)
year, varchar(10)
company, varchar(25)
number, varchar(15)
notes, varchar(250)
quantity, varchar(10)
Both tables have identical table setups, same key IDs, and type/lengths.
select distinct sum(quantity) as quantity, lastname from Database.tableone group by lastname order by quantity; \ This sets the quantities from all IDs to combine if they have the same lastname, ordered by quantity
select * from tableone left outer join tabletwo on tableone.company; \this I think joins both tables by company...im on the right path on this, i just dont know exactly where to correct.
原帖地å€: TechSpott - Computer and technology forums http://www.techspott.com//showthread.php?p=4756
What should I change in the second command to combine both(or more) tables, and sort by quantities, and names.