join

how to use sql connection in PHP to execute a query on two databases

how can i run a query that joins two tables from TWO different Databases in mssql_query or mysql_query in php for example $conn=mssql_connect($ip,$username,$password); mssql_select_db("DB1",$conn); $q="select A.name,B.ID from DB1.dbo.T1 A, DB2.dbo.T2 B where A.ID=B.ID"; $res=mssql_query($q); how to run such query?? ...

In Perl, how can I join elements of an array after enclosing each element in brackets?

I was trying to join elements of a Perl array. @array=('a','b','c','d','e'); $string=join(']',@array); will give me $string="a]b]c]d]e"; Is there anyway I can quickly get $string="[a][b][c][d][e]"; ? ...

SQL query: list all items in one table that do not appear in another table

I'm working on a training tracker program and I'm at a point where I cant figure out the SQL query. I have 3 tables: employees, trainingRecords, masterList. employees and trainingRecords are related through the empID fkey. trainingRecords and masterList are related through the TID fkey. Right now the training records table is bla...

SQL Joining the first, second and third row of joining table

I need to display some columns on the final result which comes from a join. Those columns comes in 3 groups, say: name_1, addr_1, prefecture_1, price_1, name_2, addr_2, prefecture_2, price_2, name_3, addr_3, prefecture_3, price_3 Where these 3 groups comes from a join which should return only 3 records according to a sort key carrier_...

DB Design question regarding intersections

Of these two designs for a crossroad database #Street street_id | street_nm #Crossing crossing_id | x | y | street_id_1 | street_id_2 VS #Street street_id | street_nm #Crossing crossing_id | x | y #street crossing relationship street_id | crossing_id Assuming every crossing has only exactly two roads, is there a reason why one wou...

Joining a subselect to a table in sql

Is it possible to join the results of a SELECT with another table. Like this: SELECT * FROM table1 LEFT OUTER JOIN (SELECT * FROM table 2) I know I need to link the column but am not sure how. Is this possible? ...

SQL - Most performant manner to conditionally exlude a join? (if it's even possible)

If I have the following table structure... Table 1: BlogPost PostId | Name | Text Table 2: Tags TagId | Tag Table 3: BlogPostTag PostId | TagId And the following stored procedure... CREATE PROCEDURE SearchBlogPosts @tagstring nvarchar(max), AS BEGIN DECLARE @searchTags TABLE (Tag varchar(50)); IF @tagst...

SQL to LINQ query, return objects AND count nicely bundled together..

An employee can have multiple vehicles.. And a company can have multiple employees.. My mission is to get the Companies that therefore have the most vehicles.. I have the LINQ query working perfectly (phew)! It returns (via select new {}).. CompanyID EmployeeVehicleCount Fantastic! BUT.. I want to be able to pull out "Company" ob...