TechSpott - Computer and technology forums

Go Back   TechSpott - Computer and technology forums > Webmasters > Database Management > MySQL
MySQL Forum dedicated to the world's most popular open source database engine.

Reply
 
Thread Tools Display Modes
Old April 6th, 2010, 04:23 AM   #1 (permalink)
rootlinuxusr
Guest
 
Posts: n/a
Default Need some help joining two MYSQL tables in the same DB, and ordering by...

...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.
  Reply With Quote Share with Facebook
Reply

Bookmarks

Tags
joining, mysql, ordering, tables


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 
Forum Stats
Members: 14,375
Threads: 20,384
Posts: 27,874
Total Online: 39

Newest Member: AAccedlyGolo

Latest Threads

Advertisements

Support our advertisers!

Amazon
Sears
Macys
1800flowers.com
Drugstore.com


Carbonite Online-Backups
Tiger Direct
Tech Depot
Buy.com
Office Depot
Fatcow
HostGator


TripsNow.us
Marriott
Expedia
CheapTickets.com
OneTravel
Hotwire

Are you a Fan?

Share this on Facebook

Tag Cloud

Partner Links


Contact Us - Home - Archive - Privacy Statement - Top - Copyright © 2009-2010, TechSpott - All times are GMT -4. Time is 09:19 PM

Powered by vBulletin® Copyright © Jelsoft Enterprises Ltd. :: SEO by vBSEO