Search Results

Search found 7706 results on 309 pages for 'inner join'.

Page 8/309 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • NHibernate Left Outer Join

    - by Matthew
    I'm looking to create a Left outer join Nhibernate query with multiple on statements akin to this: SELECT * FROM [Database].[dbo].[Posts] p LEFT JOIN [Database].[dbo].[PostInteractions] i ON p.PostId = i.PostID_TargetPost And i.UserID_ActingUser = 202 I've been fooling around with the critera and aliases, but I haven't had any luck figuring out how do to this. Any suggestions?

    Read the article

  • SQL - How to join on similar (not exact) columns

    - by BlueRaja
    I have two tables which get updated at almost the exact same time - I need to join on the datetime column. I've tried this: SELECT * FROM A, B WHERE ABS(DATEDIFF(second, A.Date_Time, B.Date_Time) = ( SELECT MIN(ABS(DATEDIFF(second, A.Date_Time, B2.Date_Time))) FROM B AS B2 ) But it tells me: Multiple columns are specified in an aggregated expression containing an outer reference. If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression. How can I join these tables?

    Read the article

  • SQL join produces one result only

    - by Rami
    Can anyone please tell me why this result is generation only one results? taking in mind that everything is set right and the three tables are populated correctly, i took out the group_concat and it worked but of course with a php undefined index error! SELECT `songs`.`song_name`, `songs`.`add_date`, `songs`.`song_id`, `songs`.`song_picture`, group_concat(DISTINCT artists.artist_name) as artist_name FROM (`songs`) JOIN `mtm_songs_artists` ON `songs`.`song_id` = `mtm_songs_artists`.`song_id` JOIN `artists` ON `artists`.`artist_id` = `mtm_songs_artists`.`artist_id` ORDER BY `songs`.`song_id` DESC LIMIT 10 so i'm guessing it's something related to group_concat. best regards, Rami

    Read the article

  • Using CASE Statements in LEFT OUTER JOIN in SQL

    - by s khan
    I've got a scenario where I want to switch on two different tables in an outer join. It goes something like this:- select mytable.id, yourtable.id from mytable left outer join (case when mytable.id = 2 then table2 yourtable on table1.id = table2.id else table3 yourtable on table1.id = table3.id end) ...but it doesn't work. Any suggestions?

    Read the article

  • join two table for insert data in database in android

    - by shadi
    I have two table(t1,t2) in android, t1 has a primary key that it is foreign key for t2,i want to insert data to this tables,is it necessary to join these two table?if yes, what is code for join these table? i insert data in one of them like this: public long insertQuote(String Quote,int Count1 ) { ContentValues initialValues = new ContentValues(); initialValues.put(GoodName, Quote); initialValues.put(CartID, Count1); return db.insert(DATABASE_TABLE, null, initialValues); }

    Read the article

  • web application , join event on facebook using php api

    - by Mohammed Al-shareif
    enter code herei created my events on facebook throw php api (form my website) ...every thing its fine with me and the events appear 100% on FB calendar , i got the FB event id and save to my db , enter code here my users can join the same event on my website i need them to join the same event on facebook also i have the facebook event id , and user accept my permission to access his/here calendar please anybody help!!!

    Read the article

  • entity framework join

    - by Luca Romagnoli
    Hi, i have 2 table (user, user_profile) without a explicit relationship in the sql db. and i can't add it to the db. so, i can't do this: db.user.include("user_profile") the attribute in for the join is user_id is possible do anything like this? db.user.join("user_profile On user.id = user_profile.user_id") How can i do that? thanks

    Read the article

  • Appending a prefix when using join in Perl

    - by syker
    I have an array of strings that I would like to use the join function on. However, I would like to prefix each string with the same string. Can I do this in one line as opposed to iterating through the array first and changing each value before using join?

    Read the article

  • linq to entites left outer join

    - by parminder
    I am struggling linq to entities left outer join. I have two entities (tables): Listings { ListingID, MakeID (nullable) } Makes { MakeID, Description } I want to write something like this in LINQ: select listings.listingID ,listings.makeid , IsNull(makes.Description, 'NA') from listings left outer join makes on listings.makeid = makes.makeid

    Read the article

  • Data retrieval and Join operations with cluster db server

    - by Goerge
    If any database spreads across multiple servers (ex. Microsoft Sql Server), how can we do join or filter operations. In my scenario, if suppose: A single table spreads across multiple servers how can we filter rows based on user input? If master table is there on one db server and transaction table is at another db server, how can we do join operations? Please let me know how can we achieve this and where can I get more details about this?

    Read the article

  • LINQ 2 SQL:Left outer join for my SQL statement

    - by Shyju
    Can any one tell me the LINQ 2 SQL version (in vb.net) of the below Left outer join query.I am trying to get all Employees with name "Shyju" and their address line 1 if it exist in the address table SELECT E.EMPLOYEE_NAME, E.AGE,A.ADRESS_LINE1 FROM EMPLOYEE_MASTER E LEFT OUTER JOIN ADDRESS_MASTER A ON E.ID=A.EMPLOYEE_ID WHERE E.EMPLOYEE_NAME='Shyju' Thanks in advance

    Read the article

  • Python: Split, strip, and join in one line

    - by PandemoniumSyndicate
    I'm curious if their is some python magic I may not know to accomplish a bit of frivolity given the line: csvData.append(','.join([line.split(":").strip() for x in L])) I'm attempting to split a line on :, trim whitespace around it, and join on , problem is, since the array is returned from line.split(":"), the for x in L #<== L doesn't exist! causes issues since I have no name for the array returned by line.split(":") So I'm curious if there is a sexy piece of syntax I could use to accomplish this in one shot? Cheers!

    Read the article

  • MySQL: Use CASE/ELSE value as join parameter

    - by DRJ
    I'm trying to join the NAME and PHOTO from USERS table to the TRANSACTIONS table based on who is the payer or payee. It keeps telling me can't find the table this -- What am I doing wrong? SELECT name,photo,amount,comment, ( CASE payer_id WHEN 72823 THEN payee_id ELSE payer_id END ) AS this FROM transactions RIGHT JOIN users ON (users.id=this) WHERE payee_id=72823 OR payer_id=72823

    Read the article

  • Join two results in Powershell

    - by Hinek
    I've got two CMDlets that return lists of objects. One returns objects of the type SPSolution, which contains the property Id, the other returns objects of the type SPFeature with a property SolutionId. Now I want to join/merge this data something like this: $f = Get-Feature $s = Get-Solution $result = <JOIN> $f $s <ON> $f.SolutionId = $s.Id <SELECT> FeatureName = $f.DisplayName, SolutionName = $s.Name

    Read the article

  • Complex multiple join query across 3 tables

    - by Keir Simmons
    I have 3 tables: shops, PRIMARY KEY cid,zbid shop_items, PRIMARY KEY id shop_inventory, PRIMARY KEY id shops a is related to shop_items b by the following: a.cid=b.cid AND a.zbid=b.szbid shops is not directly related to shop_inventory shop_items b is related to shop_inventory c by the following: b.cid=c.cid AND b.id=c.iid Now, I would like to run a query which returns a.* (all columns from shops). That would be: SELECT a.* FROM shops a WHERE a.cid=1 AND a.zbid!=0 Note that the WHERE clause is necessary. Next, I want to return the number of items in each shop: SELECT a.*, COUNT(b.id) items FROM shops a LEFT JOIN shop_items b ON b.cid=a.cid AND b.szbid=a.zbid WHERE a.cid=1 GROUP BY b.szbid,b.cid As you can see, I have added a GROUP BY clause for this to work. Next, I want to return the average price of each item in the shop. This isn't too hard: SELECT a.*, COUNT(b.id) items, AVG(COALESCE(b.price,0)) average_price FROM shops a LEFT JOIN shop_items b ON b.cid=a.cid AND b.szbid=a.zbid WHERE a.cid=1 GROUP BY b.szbid,b.cid My next criteria is where it gets complicated. I also want to return the unique buyers for each shop. This can be done by querying shop_inventory c, getting the COUNT(DISTINCT c.zbid). Now remember how these tables are related; this should only be done for the rows in c which relate to an item in b which is owned by the respective shop, a. I tried doing the following: SELECT a.*, COUNT(b.id) items, AVG(COALESCE(b.price,0)) average_price, COUNT(DISTINCT c.zbid) FROM shops a LEFT JOIN shop_items b ON b.cid=a.cid AND b.szbid=a.zbid LEFT JOIN shop_inventory c ON c.cid=b.cid AND c.iid=b.id WHERE a.cid=1 GROUP BY b.szbid,b.cid However, this did not work as it messed up the items value. What is the proper way to achieve this result? I also want to be able to return the total number of purchases made in each shop. This would be done by looking at shop_inventory c and adding up the c.quantity value for each shop. How would I add that in as well?

    Read the article

  • LINQ Joins - Performance

    - by Meiscooldude
    I am curious on how exactly LINQ (not LINQ to SQL) is performing is joins behind the scenes in relation to how Sql Server performs joins. Sql Server before executing a query, generates an Execution Plan. The Execution Plan is basically an Expression Tree on what it believes is the best way to execute the query. Each node provides information on whether to do a Sort, Scan, Select, Join, ect. On a 'Join' node in our execution plan, we can see three possible algorithms; Hash Join, Merge Join, and Nested Loops Join. Sql Server will choose which algorithm to for each Join operation based on expected number of rows in Inner and Outer tables, what type of join we are doing (some algorithms don't support all types of joins), whether we need data ordered, and probably many other factors. Join Algorithms: Nested Loop Join: Best for small inputs, can be optimized with ordered inner table. Merge Join: Best for medium to large inputs sorted inputs, or an output that needs to be ordered. Hash Join: Best for medium to large inputs, can be parallelized to scale linearly. LINQ Query: DataTable firstTable, secondTable; ... var rows = from firstRow in firstTable.AsEnumerable () join secondRow in secondTable.AsEnumerable () on firstRow.Field<object> (randomObject.Property) equals secondRow.Field<object> (randomObject.Property) select new {firstRow, secondRow}; SQL Query: SELECT * FROM firstTable fT INNER JOIN secondTable sT ON fT.Property = sT.Property Sql Server might use a Nested Loop Join if it knows there are a small number of rows from each table, a merge join if it knows one of the tables has an index, and Hash join if it knows there are a lot of rows on either table and neither has an index. Does Linq choose its algorithm for joins? or does it always use one?

    Read the article

  • showing null rows using join

    - by Pradyut Bhattacharya
    Hi, In mysql i m selecting from a table shouts having a foreign key to another table named "roleuser" with the matching column as user_id Now the user_id column in the shouts table for some rows is null (not actually null but with no inserts in mysql) How to show all the rows of the shouts table either with user_id null or not I m executing the sql statement SELECT s.*, r.firstname, r.lastname FROM shouts s left join roleuser r where r.user_id = s.user_id limit 50; which does not executes and shows You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where r.user_id = s.user_id limit 50' at line 2 but using inner join the sql executes which shows rows which only have user_id values in the shouts table. the nulls are not shown. SELECT s.*, r.firstname, r.lastname FROM shouts s inner join roleuser r where r.user_id = s.user_id limit 50; How can i show all the rows from the shouts table and null values in the firstname and lastname columns where the user_id is null in the shouts table. If not at all possible with sql may be using stored procedures... Thanks Pradyut

    Read the article

  • Problem with duplicates in a SQL Join

    - by Chris Ballance
    I have the following result set from a join of three tables, an articles table, a products table, an articles to products mapping table. I would like to have the results with duplicates removed similar to a select distinct on content id. Current result set: [ContendId] [Title] [productId] 1 article one 2 1 article one 3 1 article one 9 4 article four 1 4 article four 10 4 article four 14 5 article five 1 6 article six 8 6 article six 10 6 article six 11 6 article six 13 7 article seven 14 Desired result set: [ContendId] [Title] [productId] 1 article one * 4 article four * 5 article five * 6 article six * 7 article seven * Here is condensed example of the relevant SQL: IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'tempdb.dbo.products') AND type = (N'U')) drop table tempdb.dbo.products go CREATE TABLE tempdb.dbo.products ( productid int, productname varchar(255) ) go IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'articles') AND type = (N'U')) drop table tempdb.dbo.articles go create table tempdb.dbo.articles ( contentid int, title varchar(255) ) IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'articles') AND type = (N'U')) drop table tempdb.dbo.articles go create table tempdb.dbo.articles ( contentid int, title varchar(255) ) IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'articleproducts') AND type = (N'U')) drop table tempdb.dbo.articleproducts go create table tempdb.dbo.articleproducts ( contentid int, productid int ) insert into tempdb.dbo.products values (1,'product one'), (2,'product two'), (3,'product three'), (4,'product four'), (5,'product five'), (6,'product six'), (7,'product seven'), (8,'product eigth'), (9,'product nine'), (10,'product ten'), (11,'product eleven'), (12,'product twelve'), (13,'product thirteen'), (14,'product fourteen') insert into tempdb.dbo.articles VALUES (1,'article one'), (2, 'article two'), (3, 'article three'), (4, 'article four'), (5, 'article five'), (6, 'article six'), (7, 'article seven'), (8, 'article eight'), (9, 'article nine'), (10, 'article ten') INSERT INTO tempdb.dbo.articleproducts VALUES (1,2), (1,3), (1,9), (4,1), (4,10), (4,14), (5,1), (6,8), (6,10), (6,11), (6,13), (7,14) GO select DISTINCT(a.contentid), a.title, p.productid from articles a JOIN articleproducts ap ON a.contentid = ap.contentid JOIN products p ON a.contentid = ap.contentid AND p.productid = ap.productid ORDER BY a.contentid

    Read the article

  • MySQL LEFT JOIN, INNER JOIN etc, complicated query, PHP + MySQL for a forum

    - by Sven Eriksson
    So I've got a little forum I'm trying to get data for, there are 4 tables, forum, forum_posts, forum_threads and users. What i'm trying to do is to get the latest post for each forum and giving the user a sneak peek of that post, i want to get the number of posts and number of threads in each forum aswell. Also, i want to do this in one query. So here's what i came up with: SELECT lfx_forum_posts.*, lfx_forum.*, COUNT(lfx_forum_posts.pid) as posts_count, lfx_users.username, lfx_users.uid, lfx_forum_threads.tid, lfx_forum_threads.parent_forum as t_parent, lfx_forum_threads.text as t_text, COUNT(lfx_forum_threads.tid) as thread_count FROM lfx_forum LEFT JOIN (lfx_forum_threads INNER JOIN (lfx_forum_posts INNER JOIN lfx_users ON lfx_users.uid = lfx_forum_posts.author) ON lfx_forum_threads.tid = lfx_forum_posts.parent_thread AND lfx_forum_posts.pid = (SELECT MAX(lfx_forum_posts.pid) FROM lfx_forum_posts WHERE lfx_forum_posts.parent_forum = lfx_forum.fid GROUP BY lfx_forum_posts.parent_forum) ) ON lfx_forum.fid = lfx_forum_posts.parent_forum GROUP BY lfx_forum.fid ORDER BY lfx_forum.fid ASC This get the latest post in each forum and gives me a sneakpeek of it, the problem is that lfx_forum_posts.pid = (SELECT MAX(lfx_forum_posts.pid) FROM lfx_forum_posts WHERE lfx_forum_posts.parent_forum = lfx_forum.fid GROUP BY lfx_forum_posts.parent_forum) Makes my COUNT(lfx_forum_posts.pid) go to one (aswell as the COUNT(lfx_forum_threads.tid) which isn't how i would like it to work. My question is: is there some somewhat easy way to make it show the correct number and at the same time fetch the correct post info (the latest one that is)? If something is unclear please tell and i'll try to explain my issue further, it's my first time posting something here.

    Read the article

  • Display a ranking grid for game : optimization of left outer join and find a player

    - by Jerome C.
    Hello, I want to do a ranking grid. I have a table with different values indexed by a key: Table SimpleValue : key varchar, value int, playerId int I have a player which have several SimpleValue. Table Player: id int, nickname varchar Now imagine these records: SimpleValue: Key value playerId for 1 1 int 2 1 agi 2 1 lvl 5 1 for 6 2 int 3 2 agi 1 2 lvl 4 2 Player: id nickname 1 Bob 2 John I want to display a rank of these players on various SimpleValue. Something like: nickname for lvl Bob 1 5 John 6 4 For the moment I generate an sql query based on which SimpleValue key you want to display and on which SimpleValue key you want to order players. eg: I want to display 'lvl' and 'for' of each player and order them on the 'lvl' The generated query is: SELECT p.nickname as nickname, v1.value as lvl, v2.value as for FROM Player p LEFT OUTER JOIN SimpleValue v1 ON p.id=v1.playerId and v1.key = 'lvl' LEFT OUTER JOIN SimpleValue v2 ON p.id=v2.playerId and v2.key = 'for' ORDER BY v1.value This query runs perfectly. BUT if I want to display 10 different values, it generates 10 'left outer join'. Is there a way to simplify this query ? I've got a second question: Is there a way to display a portion of this ranking. Imagine I've 1000 players and I want to display TOP 10, I use the LIMIT keyword. Now I want to display the rank of the player Bob which is 326/1000 and I want to display 5 rank player above and below (so from 321 to 331 position). How can I achieve it ? thanks.

    Read the article

  • MYSQL JOIN WHERE ISSUES - need some kind of if condition

    - by Breezer
    Hi Well this will be hard to explain but ill do my best The thing is i have 4 tables all with a specific column to relate to eachother. 1 table with users(agent_users) , 1 with working hours(agent_pers), 1 with sold items(agent_stat),1 with project(agent_pro) the user and the project table is irrelevant in the issue at hand but to give you a better understanding why certain tables is included in my query i decided to still mention them =) The thing is that I use 2 pages to insert data to the working hour and the sold items during that time tables, then i have a third page to summarize everything for current month, the query for that is as following: SELECT *, SUM(sv_p_kom),SUM(sv_p_gick),SUM(sv_p_lunch) FROM (( agent_users LEFT JOIN agent_pers ON agent_users.sv_aid = agent_pers.sv_p_uid) LEFT JOIN agent_stat ON agent_pers.sv_p_uid = agent_stat.sv_s_uid) LEFT JOIN agent_pro ON agent_pers.sv_p_pid=agent_pro.p_id WHERE MONTH(agent_pers.sv_p_datum) =7 GROUP BY sv_aname so the problem is now that i dont want sold items from previous months to get included in the data received, i know i could solve that by simple adding in the WHERE part MONTH(agent_stat.sv_s_datum) =7 but then if no items been sold that month no data at all will show up not the time or anything. Any aid on how i could solve this is greatly appreciated. if there's something that's not so clear dont hesitate to ask and ill try my best to answer. after all my english isn't the best out there :P regards breezer

    Read the article

  • How to output JOINed tables?

    - by ilhan
    $id=(int)$_GET["id"]; $result = mysql_query("SELECT questionstable.*, categorytable.name FROM questionstable INNER JOIN categorytable ON categorytable.id = questionstable.category WHERE id=$id"); $row = mysql_fetch_assoc($result); Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.4.0\www\scsoru.php on line 33

    Read the article

  • Join query in doctrine symfony

    - by THOmas
    I have two tables userdetails and blog question The schema is UserDetails: connection: doctrine tableName: user_details columns: id: type: integer(8) fixed: false name: type: string(255) fixed: false BlogQuestion: connection: doctrine tableName: blog_question columns: question_id: type: integer(8) fixed: false unsigned: false primary: true autoincrement: true blog_id: type: integer(8) fixed: false user_id: type: integer(8) fixed: false question_title: type: string(255) I am using one join query for retrieving all the questions and user details from this two tables My join query is $q = Doctrine_Query::create() ->select('*') ->from('BlogQuestion u') ->leftJoin('u.UserDetails p'); $q->execute(); But it is showing this error Unknown relation alias UserDetails Pls anybody help me Thanks in advance

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >