Guest Posted February 13, 2017 Share Posted February 13, 2017 I have been converting mysql to sqlite and for basic queries have had good success but I ran across this one I can figure out how to convert its a bit over my head can someone help SELECT a.key, a.data, a.date_added FROM ((SELECT ('customer_' || ca.key) AS `key`, ca.data, ca.date_added FROM `customer_activity` ca) UNION (SELECT ('affiliate_' || aa.key) AS `key`, aa.data, aa.date_added FROM `affiliate_activity` aa)) a ORDER BY a.date_added DESC LIMIT 0,5 I get this error Query Error: near "UNION": syntax error Unable to execute statement Thanks Quote Link to comment https://forums.phpfreaks.com/topic/303178-mysql-to-sqlite-conversion-trouble/ Share on other sites More sharing options...
Barand Posted February 13, 2017 Share Posted February 13, 2017 Perhaps it is suffering from a surfeit of parentheses. Quote Link to comment https://forums.phpfreaks.com/topic/303178-mysql-to-sqlite-conversion-trouble/#findComment-1542692 Share on other sites More sharing options...
Guest Posted February 14, 2017 Share Posted February 14, 2017 Took some trys but I think that might just have been the issue SELECT a.key, a.data, a.date_added FROM (SELECT ('customer_' || ca.key) AS `key`, ca.data, ca.date_added FROM `customer_activity` ca UNION SELECT ('affiliate_' || aa.key) AS `key`, aa.data, aa.date_added FROM `affiliate_activity` aa) a ORDER BY a.date_added DESC LIMIT 0,5 That looks like it works! Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/303178-mysql-to-sqlite-conversion-trouble/#findComment-1542726 Share on other sites More sharing options...
Jacques1 Posted February 14, 2017 Share Posted February 14, 2017 What's the matter with those random subselects? Just do a union of two queries: SELECT 'customer_' || ca.key AS key, ca.data, ca.date_added FROM customer_activity AS ca UNION SELECT 'affiliate_' || aa.key, aa.data, aa.date_added FROM affiliate_activity AS aa ORDER BY date_added DESC LIMIT 0, 5 ; Quote Link to comment https://forums.phpfreaks.com/topic/303178-mysql-to-sqlite-conversion-trouble/#findComment-1542727 Share on other sites More sharing options...
Guest Posted February 14, 2017 Share Posted February 14, 2017 @Jacques1 would that be more efficient? Also did you format that by hand or use a tool? I came across another one that throws something into the mix I dont know anything about the LEFT JOIN SELECT `or`.order_recurring_id, `or`.order_id, `or`.reference, `or`.`status`, `or`.`date_added`, CONCAT(`o`.firstname, ' ', `o`.lastname) AS customer FROM `order_recurring` `or` LEFT JOIN `order` `o` ON (`or`.order_id = `o`.order_id) ORDER BY or.order_recurring_id DESC LIMIT 0,20 Query Error: near "or": syntax error Unable to execute statement Im assuming its the first `or` where the error is but it looks good to me (is there a way to tell where a sqlite error occured? like character count or something) Quote Link to comment https://forums.phpfreaks.com/topic/303178-mysql-to-sqlite-conversion-trouble/#findComment-1542730 Share on other sites More sharing options...
Jacques1 Posted February 14, 2017 Share Posted February 14, 2017 “OR” is a reserved word in SQL, representing the logical “OR” operation. It's theoretically possible to use it anyway if you always(!) put it in quotes, but this is very bad style and a bad habit you need to get rid of. Don't use reserved words as identifiers, and don't clutter your queries with backticks. Whether those cryptic aliases even make sense is also questionable, because they don't exactly improve readability. If typing a few characters annoys you so much, use a proper IDE with SQL autocompletion. Quote Link to comment https://forums.phpfreaks.com/topic/303178-mysql-to-sqlite-conversion-trouble/#findComment-1542731 Share on other sites More sharing options...
Guest Posted February 15, 2017 Share Posted February 15, 2017 That was it! I thought it was something more complicated I didnt make these sql statements im just converting a script so didnt have any say in the or Thank you guys! Quote Link to comment https://forums.phpfreaks.com/topic/303178-mysql-to-sqlite-conversion-trouble/#findComment-1542763 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.