![]() |
| Domain Name Sales | Domain Software | Calculate UK Domain Drop Dates | Domain Registration | NameDrive | Domain Parking | Subscribe to our Domains For Sale newsletter |
| | ||||||
| Home | Register | Rules | Membership Upgrade | Domains For Sale | Domain Name Escrow | Mark Forums Read | Domain Classified | Chat Room |
| Scripts and Coding PHP, MySQL, scripts |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
![]() | Transact SQL Help
I am actually using SQL Server 2005, but I am sure this is such a fundamental simple problem that any Transact SQL would do. If anyone knows the answer I'd really appreciate the help - I am missing something very simple here! I have 3 or more tables with various columns, but all having 1 column in common. I want to perform a query that picks the top x records, or from x+1 to y, from table 1 when ordered by the common column, then data from table 2 and table 3 using the same column. I can do it with 2 tables using Top and a Join, but struggle extending it beyond 2 tables. So I currently have: SELECT TOP 6 table1.CommonColumn, table1.AnotherColumn, table2.DifferentColumn1, table2.DifferentColumn2 FROM table1 Join table2 On table1.CommonColumn = table2.CommonColumn WHERE table1.SomeColumn = Value AND table1.CommonColumn NOT IN (SELECT TOP 12 table1.CommonColumn FROM table1 WHERE table1.SomeColumn = Value) order by table1.CommonColumn I need to extend it to return table3.DifferentColumn3, table3.DifferentColumn4 with table1.CommonColumn = table3.CommonColumn. It's POETS day and I would rather be sloping off to the pub for a sneaky pint. Any help very gratefully received.... |
| |
| | #3 (permalink) | |
![]() | Quote:
Thanks very much for the reply, I'll give it a go! Cheers Bob. | |
| |
| | #4 (permalink) |
![]() |
SELECT TOP 6 table1.*, table2.*, table3.* FROM table1 Join table2 On table1.CommonColumn = table2.CommonColumn Join table3 On table1.CommonColumn = table3.CommonColumn WHERE table1.SomeColumn = Value etc.. you might need FULL OUTER JOIN instead of just join if you don't have the same commoncolumn in all 3 tables but still want a reecord returned. |
| |
| | #6 (permalink) | |
![]() | Quote:
Thanks again. | |
| |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Domain Name Community | Replies | Last Post |
| Experienced .Net / SQL Developer | cm1975 | Services Wanted | 0 | 15-09-2009 09:58:11 AM |
| SQL Injection Problem | stevebrowne | General Board | 5 | 17-06-2008 07:47:43 PM |
| Blocking Web Sites in ISA Server - SQL Server Magazine (subscription) | RSS | Domain Name News | 0 | 26-12-2006 03:59:06 PM |
| sql injection, watch this | ONExFOUR | General Board | 10 | 30-10-2006 01:26:33 AM |