Search Results

Search found 6841 results on 274 pages for 'outer join'.

Page 6/274 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Linq, Left Join and Dates...

    - by BitFiddler
    So my situation is that I have a linq-to-sql model that does not allow dates to be null in one of my tables. This is intended, because the database does not allow nulls in that field. My problem, is that when I try to write a Linq query with this model, I cannot do a left join with that table anymore because the date is not a 'nullable' field and so I can't compare it to "Nothing". Example: There is a Movie table, {ID,MovieTitle}, and a Showings table, {ID,MovieID,ShowingTime,Location} Now I am trying to write a statement that will return all those movies that have no showings. In T.SQL this would look like: Select m.* From Movies m Left Join Showings s On m.ID = s.MovieID Where s.ShowingTime is Null Now in this situation I could test for Null on the 'Location' field but this is not what I have in reality (just a simplified example). All I have are non-null dates. I am trying to write in Linq: From m In dbContext.Movies _ Group Join s In Showings on m.ID Equals s.MovieID into MovieShowings = Group _ From ms In MovieShowings.DefaultIfEmpty _ Where ms.ShowingTime is Nothing _ Select ms However I am getting an error saying 'Is' operator does not accept operands of type 'Date'. Operands must be reference or nullable types. Is there any way around this? The model is correct, there should never be a null in the Showings:ShowTime table. But if you do a left join, and there are no show times for a particular movie, then ShowTime SHOULD be Nothing for that movie... Thanks everyone for your help.

    Read the article

  • Cross join (pivot) with n-n table containing values

    - by Styx31
    I have 3 tables : TABLE MyColumn ( ColumnId INT NOT NULL, Label VARCHAR(80) NOT NULL, PRIMARY KEY (ColumnId) ) TABLE MyPeriod ( PeriodId CHAR(6) NOT NULL, -- format yyyyMM Label VARCHAR(80) NOT NULL, PRIMARY KEY (PeriodId) ) TABLE MyValue ( ColumnId INT NOT NULL, PeriodId CHAR(6) NOT NULL, Amount DECIMAL(8, 4) NOT NULL, PRIMARY KEY (ColumnId, PeriodId), FOREIGN KEY (ColumnId) REFERENCES MyColumn(ColumnId), FOREIGN KEY (PeriodId) REFERENCES MyPeriod(PeriodId) ) MyValue's rows are only created when a real value is provided. I want my results in a tabular way, as : Column | Month 1 | Month 2 | Month 4 | Month 5 | Potatoes | 25.00 | 5.00 | 1.60 | NULL | Apples | 2.00 | 1.50 | NULL | NULL | I have successfully created a cross-join : SELECT MyColumn.Label AS [Column], MyPeriod.Label AS [Period], ISNULL(MyValue.Amount, 0) AS [Value] FROM MyColumn CROSS JOIN MyPeriod LEFT OUTER JOIN MyValue ON (MyValue.ColumnId = MyColumn.ColumnId AND MyValue.PeriodId = MyPeriod.PeriodId) Or, in linq : from p in MyPeriods from c in MyColumns join v in MyValues on new { c.ColumnId, p.PeriodId } equals new { v.ColumnId, v.PeriodId } into values from nv in values.DefaultIfEmpty() select new { Column = c.Label, Period = p.Label, Value = nv.Amount } And seen how to create a pivot in linq (here or here) : (assuming MyDatas is a view with the result of the previous query) : from c in MyDatas group c by c.Column into line select new { Column = line.Key, Month1 = line.Where(l => l.Period == "Month 1").Sum(l => l.Value), Month2 = line.Where(l => l.Period == "Month 2").Sum(l => l.Value), Month3 = line.Where(l => l.Period == "Month 3").Sum(l => l.Value), Month4 = line.Where(l => l.Period == "Month 4").Sum(l => l.Value) } But I want to find a way to create a resultset with, if possible, Month1, ... properties dynamic. Note : A solution which results in a n+1 query : from c in MyDatas group c by c.Column into line select new { Column = line.Key, Months = from l in line group l by l.Period into period select new { Period = period.Key, Amount = period.Sum(l => l.Value) } }

    Read the article

  • HasMany relation inside a Join Mapping

    - by Sean McMillan
    So, I'm having a problem mapping in fluent nhibernate. I want to use a join mapping to flatten an intermediate table: Here's my structure: [Vehicle] VehicleId ... [DTVehicleValueRange] VehicleId DTVehicleValueRangeId AverageValue ... [DTValueRange] DTVehicleValueRangeId RangeMin RangeMax RangeValue Note that DTValueRange does not have a VehicleID. I want to flatten DTVehicleValueRange into my Vehicle class. Tgis works fine for AverageValue, since it's just a plain value, but I can't seem to get a ValueRange collection to map correctly. public VehicleMap() { Id(x => x.Id, "VehicleId"); Join("DTVehicleValueRange", x => { x.Optional(); x.KeyColumn("VehicleId"); x.Map(y => y.AverageValue).ReadOnly(); x.HasMany(y => y.ValueRanges).KeyColumn("DTVehicleValueRangeId"); // This Guy }); } The HasMany mapping doesn't seem to do anything if it's inside the Join. If it's outside the Join and I specify the table, it maps, but nhibernate tries to use the VehicleID, not the DTVehicleValueRangeId. What am I doing wrong?

    Read the article

  • MySQL - How do I inner join sorting the joined data

    - by Gary
    I'm trying to write a report which will join a person, their work, and their hourly wage at the time of work. I cannot seem to figure out the best way to join the person's cost when the date is less than the date of the work. Let's say a person cost $30 per hour at the start of the year then got a $10 raise o Feb 5 and another on Mar 1. 01/01/2010 $30.00 (per hour) 02/05/2010 $40.00 03/01/2010 $45.00 The person put in hours several days which span the rasies. 01/05/2010 10 hours (should be at $30/hr) 01/27/2010 5 hours (again at $30) 02/10/2010 10 hours (at $40/hr) 03/03/2010 5 hours (at $45/hr) I'm trying to write one SQL statement which will pull the hours, the cost per hour, and the hours*cost. The cost is the hourly rate last entered into the system so the cost date is less than the work date, ordered by cost date limit 1. SELECT person.id, person.name, work.hours, person_costs.value, work.hours * person_costs.value AS value FROM person INNER JOIN work ON (person.id = work.person_id) INNER JOIN person_costs ON (person.id = person_costs.person_id AND person_costs.date < work.date) WHERE person.id = 1234 ORDER BY work.date ASC The problem I'm having, the person_costs isn't ordered by date in descending order. It's pulling out "any" value (naturally sorted by record position) which matches the condition. How do I select the first person_cost value which is older than the work date? Thanks!

    Read the article

  • SQL: Speed Improvement - Cluttered union query

    - by vol7ron
    SELECT * FROM ( SELECT a.user_id, a.f_name, a.l_name, b.user_id, b.f_name, b.l_name FROM current_tbl a INNER JOIN import_tbl b ON ( a.user_id = b.user_id ) UNION SELECT a.user_id, a.f_name, a.l_name, b.user_id, b.f_name, b.l_name FROM current_tbl a INNER JOIN import_tbl b ON ( lower(a.f_name)=lower(b.f_name) AND lower(a.l_name)=lower(b.l_name) ) ) foo -- UNION -- SELECT a.user_id , a.f_name , a.l_name , '' , '' , '' FROM current_tbl a WHERE a.user_id NOT IN ( select user_id from( SELECT a.user_id, a.f_name, a.l_name, b.user_id, b.f_name, b.l_name FROM current_tbl a INNER JOIN import_tbl b ON ( a.user_id = b.user_id ) UNION SELECT a.user_id, a.f_name, a.l_name, b.user_id, b.f_name, b.l_name FROM current_tbl a INNER JOIN import_tbl b ON ( lower(a.f_name)=lower(b.f_name) AND lower(a.l_name)=lower(b.l_name) ) ) bar ) ORDER BY user_id Example of table population: current_tbl: ------------------------------- user_id | f_name | l_name ---------+----------+---------- A1 | Adam | Acorn A2 | Beth | Berry A3 | Calv | Chard | | import_tbl: ------------------------------- user_id | f_name | l_name ---------+----------+---------- A1 | Adam | Acorn A2 | Beth | Butcher <- last_name different | | Expected Output: ----------------------------------------------------------------------- user_id1 | f_name1 | l_name1 | user_id2 | f_name2 | l_name2 ----------+-----------+-----------+------------+-----------+----------- A1 | Adam | Acorn | A1 | Adam | Acorn A2 | Beth | Berry | A2 | Beth | Butcher A3 | Calv | Chard | | | Doing this method gets rid of conditions where the row would be: A2 | Beth | Berry | A2 | Beth | Butcher But it keeps the A3 row I hope this makes sense and I haven't overly simplified it. This is a continuation question from my other question. The succession of these improvements has dropped the query down from ~32000ms to where it's at now ~1200ms - quite an improvement. I supect I can optimize by using UNION ALL in the subquery and of course the usual index optimizations, but I'm looking for the best SQL optimization. FYI this particular case is for PostgreSQL.

    Read the article

  • Updating join fields in an ORM command

    - by Jono
    I have a question about object relational updates on join fields. I am working on a project using codeigniter with datamapper dmz. But I think my problem is with general understanding of ORMs. So fell free to answer with any ORM you know. I have two tables, Goods and Tags. One good can have many tags. Everything is working, but I am looking for a way to merge tags. Meaning I decide I want to remove tag A and instead have everything that is tagged by it, now be tagged by tag B. I only have models for the goods and the tags. There is no separate model for the join relationship, as I believe these ORMs were designed to work. I know how to delete a tag. But I dont know how to reach into the join table to redirect the references since there is no model for the join table. I would rather use the ORM then issuing a raw SQL command.

    Read the article

  • SQL Server 2008 - Keyword search using table Join

    - by Aaron Wagner
    Ok, I created a Stored Procedure that, among other things, is searching 5 columns for a particular keyword. To accomplish this, I have the keywords parameter being split out by a function and returned as a table. Then I do a Left Join on that table, using a LIKE constraint. So, I had this working beautifully, and then all of the sudden it stops working. Now it is returning every row, instead of just the rows it needs. The other caveat, is that if the keyword parameter is empty, it should ignore it. Given what's below, is there A) a glaring mistake, or B) a more efficient way to approach this? Here is what I have currently: ALTER PROCEDURE [dbo].[usp_getOppsPaged] @startRowIndex int, @maximumRows int, @city varchar(100) = NULL, @state char(2) = NULL, @zip varchar(10) = NULL, @classification varchar(15) = NULL, @startDateMin date = NULL, @startDateMax date = NULL, @endDateMin date = NULL, @endDateMax date = NULL, @keywords varchar(400) = NULL AS BEGIN SET NOCOUNT ON; ;WITH Results_CTE AS ( SELECT opportunities.*, organizations.*, departments.dept_name, departments.dept_address, departments.dept_building_name, departments.dept_suite_num, departments.dept_city, departments.dept_state, departments.dept_zip, departments.dept_international_address, departments.dept_phone, departments.dept_website, departments.dept_gen_list, ROW_NUMBER() OVER (ORDER BY opp_id) AS RowNum FROM opportunities JOIN departments ON opportunities.dept_id = departments.dept_id JOIN organizations ON departments.org_id=organizations.org_id LEFT JOIN Split(',',@keywords) AS kw ON (title LIKE '%'+kw.s+'%' OR [description] LIKE '%'+kw.s+'%' OR tasks LIKE '%'+kw.s+'%' OR requirements LIKE '%'+kw.s+'%' OR comments LIKE '%'+kw.s+'%') WHERE ( (@city IS NOT NULL AND (city LIKE '%'+@city+'%' OR dept_city LIKE '%'+@city+'%' OR org_city LIKE '%'+@city+'%')) OR (@state IS NOT NULL AND ([state] = @state OR dept_state = @state OR org_state = @state)) OR (@zip IS NOT NULL AND (zip = @zip OR dept_zip = @zip OR org_zip = @zip)) OR (@classification IS NOT NULL AND (classification LIKE '%'+@classification+'%')) OR ((@startDateMin IS NOT NULL AND @startDateMax IS NOT NULL) AND ([start_date] BETWEEN @startDateMin AND @startDateMax)) OR ((@endDateMin IS NOT NULL AND @endDateMax IS NOT NULL) AND ([end_date] BETWEEN @endDateMin AND @endDateMax)) OR ( (@city IS NULL AND @state IS NULL AND @zip IS NULL AND @classification IS NULL AND @startDateMin IS NULL AND @startDateMax IS NULL AND @endDateMin IS NULL AND @endDateMin IS NULL) ) ) ) SELECT * FROM Results_CTE WHERE RowNum >= @startRowIndex AND RowNum < @startRowIndex + @maximumRows; END

    Read the article

  • SQL UNION ALL with a INNER JOIN

    - by kOhm
    I'm looking for the best way to display all rows from two tables while joining first by one field (dwg) then where applicable a 2nd join on part. Table1 data consists of schematics(dwg) along with a list of parts required to build the item depicted in the drawing. Table2 consists of data about the actual parts ordered to build the schematic. Some parts in table2 are a combination of parts in table1 (ex: foo and bar in table1 were ordered as foobar in table2). I can display all rows in both tables with UNION ALL, but this doesn't join on both the dwg and part fields. I looked at FULL OUTER JOIN also, but I haven't figured out how to join first by dwg, then by part. Here is an example of the data. table1 table2 dwg part qty order dwg part qty ----- ----- ----- ----- ----- ----- ----- 123 foo 1 ord1 123 foobar 1 123 bar 1 ord1 123 bracket 2 123 widget 2 ord2 123 screw 4 123 bracket 4 ord2 123 nut 4 456 foo 1 ord2 123 widget 2 ord2 123 bracket 2 ord3 456 foo 1 Desired output: The goal is to create a view that provides visibility to all parts in table1 and the associated orders in table2 (including those parts that appear in one but not the other table) so that I can see all the drawing parts in table1 and the associated records in table2 along with records in table2 where the part wasn't in table1. part_request_order_report dwg part qty order part qty ----- ----- ----- ------ ----- ----- 123 foo 1 123 bar 1 123 widget 2 ord2 widget 2 123 bracket 4 ord1 bracket 2 123 bracket 4 ord2 bracket 2 123 ord1 foobar 1 123 ord1 screw 4 123 ord1 nut 4 456 foo 1 ord3 foo 1 Is this possible? Or am I better off iterating through the data to build the report table? Thanks in advance.

    Read the article

  • SQL n:m Inheritance join

    - by Nightmares
    I want to join a table which contains n:m relationship between groups. (Groups are defined in a separate table). This table only has entries listing a member_group_id and a parent_group_id. Given this structure: id(int) | member_group_id(int) | parent_group_id(int) The "base" query looks like this: select p1.group_id, p2.group_id, p1.member_group_id, p2.member_group_id from group_member_group as p1 join group_member_group as p2 on p2.member_group_id = p1.member_group_id The "base" query correctly shows all relationships (I checked by doing it manually.) The problem is when I try to apply a where clause to this query to filter for a specific group as "point of origin" (the first group for which I want all parent groups) it returns only the closest parents. For example like this: select p1.group_id, p2.group_id, p1.member_group_id, p2.member_group_id from group_member_group as p1 join group_member_group as p2 on p2.member_group_id = p1.member_group_id where p1.group_id = 1 Can anyone give a clue how I can fix this? Or a different approach to realize this. (I suppose I could always do this in my C++ source code on the server side but I would have to transfer a entire table which has a high growth potential to the application server.) UPDATE: select p1.group_id, p2.group_id, p1.member_group_id, p2.member_group_id from group_member_group as p1 join group_member_group as p2 on p2.group_id = p1.member_group_id Typing mistake confirmed. Now I don't get past first level of inheritance period. Thanks at denied for pointing that out.

    Read the article

  • subquery in join with doctrine dql

    - by Martijn de Munnik
    I want to use DQL to create a query which looks like this in SQL: select e.* from e inner join ( select uuid, max(locale) as locale from e where locale = 'nl_NL' or locale = 'nl' group by uuid ) as e_ on e.uuid = e_.uuid and e.locale = e_.locale I tried to use QueryBuilder to generate the query and subquery. I think they do the right thing by them selves but I can't combine them in the join statement. Does anybody now if this is possible with DQL? I can't use native SQL because I want to return real objects and I don't know for which object this query is run (I only know the base class which have the uuid and locale property). $subQueryBuilder = $this->_em->createQueryBuilder(); $subQueryBuilder ->addSelect('e.uuid, max(e.locale) as locale') ->from($this->_entityName, 'e') ->where($subQueryBuilder->expr()->in('e.locale', $localeCriteria)) ->groupBy('e.uuid'); $queryBuilder = $this->_em->createQueryBuilder(); $queryBuilder ->addSelect('e') ->from($this->_entityName, 'e') ->join('('.$subQueryBuilder.') as', 'e_')->join ->where('e.uuid = e_.uuid') ->andWhere('e.locale = e_.locale');

    Read the article

  • SQL Oracle LEFT JOIN and SUBQUERY error: ORA-00905: missing keyword

    - by Curro
    Hello everyone. Asking for your help on this Oracle query. It's giving me the error 2 "ORA-00905: missing keyword". It was working fine before I added the LEFT JOIN statement. Obviously it won't deliver the information as we need it without the LEFT JOIN statement. Please provide any help to know which keyword is missing in this query Thanks a lot!: DB Tables: DW.TICKETS DW.TICKET_ACTLOG Subquery table: TABLE_RESOLVERS SELECT TO_CHAR(DW.TICKETS.RESOLVED_TIMESTAMP,'YYYY-MM-DD HH24:MI:SS') AS RESOLVED_DATE, DW.TICKETS.SUBJECT, DW.TICKETS.OWNER_CORE_ID, DW.TICKETS.TICKET_NUMBER, TABLE_RESOLVERS.SUBMITTER AS RESOLVER_CORE_ID FROM DW.TICKETS LEFT JOIN (SELECT TICKET_NUMBER, SUBMITTER FROM DW.TICKET_ACTLOG WHERE TYPE = 'Final Resolution' AND (SUBMITTER = 'B02666' OR SUBMITTER = 'R66604') ORDER BY CREATE_TIMESTAMP DESC ) AS TABLE_RESOLVERS ON DW.TICKETS.TICKET_NUMBER = TABLE_RESOLVERS.TICKET_NUMBER WHERE DW.TICKETS.RESOLVED_TIMESTAMP >= to_date('05-03-2010','dd-mm-yyyy') AND DW.TICKETS.RESOLVED_TIMESTAMP < to_date('8-03-2010','dd-mm-yyyy') AND DW.TICKETS.TICKET_NUMBER LIKE 'TCK%' AND DW.TICKETS.TICKET_NUMBER IN (SELECT TICKET_NUMBER FROM DW.TICKET_ACTLOG WHERE (SUBMITTER = 'B02666' OR SUBMITTER = 'R66604') ) ORDER BY DW.TICKETS.CREATE_TIMESTAMP ASC

    Read the article

  • Left Join in Subsonic 3

    - by user303187
    I'm trying to do a left join in subsonic 3 using linq but it doesn't seem to work, I get a big error. var post = from p in Post.All() join q in Quote.All() on p.ID equals q.PostID into pq where p.ID == id.Value from qt in pq.DefaultIfEmpty() select new {p, qt}; I'm using subsonic 3, latest GIT version from Rob, but I'm getting an error, see below, when I try a left join. I have searched but I didn't found any solution. Can anyone explain to me why the error and how to fix it? Thanks Expression of type 'System.Collections.Generic.IEnumerable1[GetAQuote.Post]' cannot be used for parameter of type 'System.Linq.IQueryable1[GetAQuote.Post]' of method 'System.Linq.IQueryable1[<>f__AnonymousType221[GetAQuote.Post], System.Collections.Generic.IEnumerable1%5BGetAQuote.Quote%5D, System.Linq.Expressions.Expression1[System.Func2%5BGetAQuote.Post,System.Int32%5D%5D, System.Linq.Expressions.Expression1[System.Func2%5BGetAQuote.Quote,System.Int32%5D%5D, System.Linq.Expressions.Expression1[System.Func3%5BGetAQuote.Post,System.Collections.Generic.IEnumerable1[GetAQuote.Quote],<>f__AnonymousType22%5BGetAQuote.Post,System.Collections.Generic.IEnumerable1%5BGetAQuote.Quote%5D%5D%5D%5D"GetAQuote.Post,System.Collections.Generic.IEnumerable1[GetAQuote.Quote]]] GroupJoin[Post,Quote,Int32,<f__AnonymousType22'`

    Read the article

  • mySQL Left Join on multiple tables with conditions

    - by Jarrod
    Hi, I have a problem. I have 4 tables: Invoice_Payment, Invoice, Client, and Calendar Basically, I have the below query, which works well, except, months with no date_due don't return. I.E only months with a date_due will be returned. I think I have to use a left join and join the calendar table with something like: LEFT JOIN Calendar ON Invoice_Payments.date_paid = Calendar.date_field. But I'm having no luck SELECT MONTHNAME(Invoice_Payments.date_paid) as month, SUM(Invoice_Payments.paid_amount) AS total FROM Invoice, Client, Invoice_Payments WHERE Client.registered_id = 1 AND Client.id = Invoice.client_id And Invoice.id = Invoice_Payments.invoice_id AND date_paid IS NOT NULL GROUP BY YEAR(Invoice_Payments.date_paid), MONTH(Invoice_Payments.date_paid) Any help appreciated.

    Read the article

  • Complex Join - involving date ranges and sum...

    - by calumbrodie
    I have two tables that I need to join... I want to join table1 and table2 on 'id' - however in table two id is not unique. I only want one value returned for table two, and this value represents the sum of a column called 'total_sold' - within a specified date range (say one month).. SELECT ta.id, tb.total_sold as total_sold_this_week FROM table_a as ta LEFT JOIN table_b as tb ON ta.id=tb.id AND tb.date_sold BETWEEN ADDDATE(NOW(),INTERVAL -3 WEEK) AND NOW() this works but does not SUM the rows - only returning one row for each id... how do I get the sum from table b instead of only one row??? Please criticise if format of question could use more work - I can rewrite and provide sample data if required - this is a trivialised version of a much larger problem. -Thanks

    Read the article

  • MYSQL Inner Join two table over two keys

    - by bertsisterwanda
    I am doing a query to return all users shopping carts, stored in the sb_carts table. The product information stored in sb_carts is referenced over two keys product_sku and school_id. It needs to reference both to return a unique product with unique stock levels etc. When I execute the following query it returns one row, I am expecting 3 rows. I have tried breaking the inner join into two separate joins but this still returns only 1 result. joining only on one key has the desired result, but may be retuning the wrong product. A left join returns 3 rows but some data is missing product specific Here is a simplified example of what I am doing SELECT sb_carts.product_sku FROM sb_carts INNER JOIN sb_products ON sb_products.sku = sb_carts.product_sku AND sb_products.school_id = sb_carts.school_id WHERE sb_carts.order_id = 0 AND sb_carts.user_id = 2 GROUP BY sb_carts.cart_id

    Read the article

  • introduce a join to this query, possible?

    - by Iain Urquhart
    I'm trying to introduce a join to this query: SELECT `n`.*, round((`n`.`rgt` - `n`.`lft` - 1) / 2, 0) AS childs, count(*) - 1 + (`n`.`lft` > 1) + 1 AS level, ((min(`p`.`rgt`) - `n`.`rgt` - (`n`.`lft` > 1)) / 2) > 0 AS lower, (((`n`.`lft` - max(`p`.`lft`) > 1))) AS upper FROM `exp_node_tree_6` `n`, `exp_node_tree_6` `p`, `exp_node_tree_6` WHERE `n`.`lft` BETWEEN `p`.`lft` AND `p`.`rgt` AND ( `p`.`node_id` != `n`.`node_id` OR `n`.`lft` = 1 ) GROUP BY `n`.`node_id` ORDER BY `n`.`lft` by adding LEFT JOIN `exp_channel_titles` ON (`n`.`entry_id`=`exp_channel_titles`.`entry_id`) after the FROM statement... But when I introduce it, it fails with "Unknown column 'n.entry_id' in 'on clause'" Is it even possible to add a join to this query? Can anybody help, thanks!

    Read the article

  • Zend Framework Db Select Join table help

    - by tester2001
    I have this query: SELECT g.title, g.asin, g.platform_id, r.rank FROM games g INNER JOIN ranks r ON ( g.id = r.game_id ) ORDER BY r.rank DESC LIMIT 5` Now, this is my JOIN using Zend_Db_Select but it gives me array error $query = $this-select(); $query-from(array('g' = 'games'), array()); $query-join(array('r' = 'ranks'), 'g.id = r.game_id', array('g.title', 'g.asin', 'g.platform_id', 'r.rank')); $query-order('r.rank DESC'); $query-limit($top); $resultRows = $this-fetchAll($query); return $resultRows; Anyone know what I could be doing wrong? I want to get all the columns in 'games' to show and the 'rank' column in the ranks table.

    Read the article

  • Double Inner Join generates unexpected error

    - by Itamar Marom
    In my database I have three tables: Users: UserID (Auto Numbering), UserName, UserPassword and a few other unimportant fields. PrivateMessages: MessageID (Auto Numbering), SenderID and a few other fields defining the message content. MessageStatus: MessageID, ReceiverID, MessageWasRead (Boolean) What I need is a query to which I input a user's id and I get all the private messages he has received. In addition, I also need to receive each message's sender UserName. For this I wrote the following query: SELECT Users.*, PrivateMessages.*, MessageStatus.* FROM PrivateMessages INNER JOIN Users ON PrivateMessages.SenderID = Users.UserID INNER JOIN MessageStatus ON PrivateMessages.MessageID = MessageStatus.MessageID WHERE MessageStatus.ReceiverID=[@userid]; But for some reason when I try saving it in my Access database, I get the following error (translated to English by me, since my office is in a different language): Syntax error (missing operator) at expression: "PrivateMessages.SenderID = Users.UserID INNER JOIN MessageStatus ON PrivateMessages.MessageID = MessageStatus.MessageI". Any ideas what could cause this? Thanks.

    Read the article

  • Getting highest results in a JOIN

    - by Keithamus
    I've got three tables; Auctions, Auction Bids and Users. The table structure looks something like this: Auctions: id title -- ----- 1 Auction 1 2 Auction 2 Auction Bids: id user_id auction_id bid_amt -- ------- ---------- ------- 1 1 1 200.00 2 2 1 202.00 3 1 2 100.00 Users is just a standard table, with id and user name. My aim is to join these tables so I can get the highest values of these bids, as well as get the usernames related to those bids; so I have a result set like so: auction_id auction_title auctionbid_amt user_username ---------- ------------- -------------- ------------- 1 Auction 1 202.00 Bidder2 2 Auction 2 100.00 Bidder1 So far my query is as follows: SELECT a.id, a.title, ab.bid_points, u.display_name FROM auction a LEFT JOIN auctionbid ab ON a.id = ab.auction_id LEFT JOIN users u ON u.id = ab.user_id GROUP BY a.id This gets the single rows I am after, but it seems to display the lowest bid_amt, not the highest.

    Read the article

  • In PHP + MySQL, How do I join many tables with conditions

    - by Moe
    Hi, I'm trying to get the users full activity throughout the website. I need to Join many tables throughout the database, with that condition that it is one user. What I currently have written is: SELECT * FROM comments AS c JOIN rphotos AS r ON c.userID = r.userID AND c.userID = '$defineUserID'; But What it is returning is everything about the user, but it repeats rows. For instance, for one user he has 6 photos and 5 comments So I expect the join to return 11 rows. Instead it returns 30 results like so: PhotoID = 1; CommentID = 1; PhotoID = 1; CommentID = 2; PhotoID = 1; CommentID = 3; and so on... What am i doing wrong?

    Read the article

  • How can I join this 2 queries?(A select query with join and An unpivot query)

    - by MANG KANOR
    Here are my two queries SELECT EWND.Position, NKey = CASE WHEN ISNULL(Translation.Name, '') = '' THEN EWND.Name ELSE Translation.Name END, Unit = EW_N_DEF.Units FROM EWND INNER JOIN EW_N_DEF ON EW_N_DEF.Nutr_No = EWND.Nutr_No LEFT JOIN Translation ON Translation.CodeMain = EWND.Nutr_no WHERE Translation.CodeTrans = 1 ORDER BY EWND.Position And this is the unpivot one SELECT * FROM (SELECT N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27,N28,N29,N30,N31,N32,N33,N34 FROM EWNVal WHERE Code=6035) Test UNPIVOT (Value FOR NUTCODE IN (N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27,N28,N29,N30,N31,N32,N33,N34) )AS test Both Queries put out same number of rows but not columns, Is it possible to join this two? I tried the union but it has problems that I cant solve Thanks in advance!

    Read the article

  • SQL-Join with NULL-columns

    - by tstenner
    I'm having the following tables: Table a +-------+------------------+------+-----+ | Field | Type | Null | Key | +-------+------------------+------+-----+ | bid | int(10) unsigned | YES | | | cid | int(10) unsigned | YES | | +-------+------------------+------+-----+ Table b +-------+------------------+------+ | Field | Type | Null | +-------+------------------+------+ | bid | int(10) unsigned | NO | | cid | int(10) unsigned | NO | | data | int(10) unsigned | NO | +-------+------------------+------+ When I want to select all rows from b where there's a corresponding bid/cid-pair in a, I simply use a natural join SELECT b.* FROM b NATURAL JOIN a; and everything is fine. When a.bid or a.cid is NULL, I want to get every row where the other column matches, e.g. if a.bid is NULL, I want every row where a.cid=b.cid, if both are NULL I want every column from b. My naive solution was this: SELECT DISTINCT b.* FROM b JOIN a ON ( ISNULL(a.bid) OR a.bid=b.bid ) AND (ISNULL(a.cid) OR a.cid=b.cid ) Is there any better way to to this?

    Read the article

  • MySQL LEFT JOIN issue with three WHERE statements

    - by jhat
    I am building a note taking app for myself with tag filtering functions, but am having an issue when trying to grab notes with the tags. The tag filter needs to use AND not IN, because it will help better narrow down what I am looking for. My tables are configured like this: + notes note_id | note_title | note_uid + tags tag_id | tag_title + notes_tags nt_id | nt_note_id | nt_tag_id The notes_tags table keeps track of all notes' tags. I am not worried about returning any information about tags, so here is an example LEFT JOIN I am using currently to only get notes with only 1 tag. SELECT * FROM notes_tags LEFT JOIN notes ON note_id = nt_note_id WHERE note_uid IN ( 1 ) AND nt_tag_id = 10 This query runs perfect, it grabs all of the notes with that single tag. However, I am having issues "pinpointing" my notes using a query like this: SELECT * FROM notes_tags LEFT JOIN notes ON note_id = nt_note_id WHERE note_uid IN ( 1 ) AND nt_tag_id = 10 AND nt_tag_id = 11 What am I doing wrong with the syntax?

    Read the article

  • Django query - join on the same table

    - by dana
    i have a mini blog app, and a 'timeline' . there i want to be displayed all the posts from all the friends of a user, plus the posts of that user himself. For that, i have to make some kind of a 'join' between the results of two queries (queries on the same table) , so that the final result will be the combination of the user - posesor of the account, and all his friends. My query looks like this: blog = New.objects.filter(created_by = following,created_by = request.user) By that ',' i wanted to make a 'join' -i found something like this on a doc- but this method is not correct- i'm getting an error. How else could be done this 'join' ? Thanks!

    Read the article

  • Displaying Data from a Join in Codeigniter

    - by Brad
    I am using a simple join to pull data from two databases. This is the join in the model function com_control(){ $this->db->select('*'); $this->db->from('comments'); $this->db->join('posts', 'comments.entry_id = posts.id'); $query = $this->db->get(); return $query->result; } My desired method of display is going to be in a table so I am starting out to use like this foreach($comm_control as $row){ $this->table->add_row( $row->entry_id, $row->comments.id, $row->comment, $row->title ); }//end of foreach My problem is the display of data from comments.id. What is the proper format to add the comment.id into the table rows? I need the ID from both tables for display, edit and delete further on in the table. The only display I get at this time for "comment.id" is the word id. The Any help would be appreciated.

    Read the article

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