Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1078763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:46:16+00:00 2026-05-16T21:46:16+00:00

I have the following mysql table schema: SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; — — Database: `network` —

  • 0

I have the following mysql table schema:

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `network`
--

-- --------------------------------------------------------

--
-- Table structure for table `contexts`
--

CREATE TABLE IF NOT EXISTS `contexts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `keyword` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

-- --------------------------------------------------------

--
-- Table structure for table `neurons`
--

CREATE TABLE IF NOT EXISTS `neurons` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

-- --------------------------------------------------------

--
-- Table structure for table `synapses`
--

CREATE TABLE IF NOT EXISTS `synapses` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `n1_id` int(11) NOT NULL,
  `n2_id` int(11) NOT NULL,
  `context_id` int(11) NOT NULL,
  `strength` double NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

What SQL can I write to get all Neurons associated with a specified context along with the sum of the strength column for the synapses associated with each neuron?

I’m using the following query, which returns the sum of the strength of the synapses associated with one neuron. I need to get information for all of the neurons:

/* This query finds how strongly the neuron with id 1 is connected to the context with keyword ice cream*/

SELECT SUM(strength) AS Strength FROM
synapses
JOIN contexts AS Context ON synapses.context_id = Context.id
JOIN neurons AS Neuron ON Neuron.id = synapses.n1_id OR Neuron.id = synapses.n2_id
WHERE Neuron.id = 1 AND Context.keyword = 'ice cream'

For example, that query returns one row, where Strength is 2. Ideally, I could have one column for the neurons.id, one for neurons.name, and one for SUM(synapses.strength) with one record for each distinct neuron.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:46:17+00:00Added an answer on May 16, 2026 at 9:46 pm

    Use:

       SELECT DISTINCT 
              n.*,
              COALESCE(x.strength, 0) AS strength
         FROM NEURONS n
         JOIN SYNAPSES s ON n.id IN (s.n1_id, s.n2_id)
         JOIN CONTEXTS c ON c.id = s.context_id
    LEFT JOIN (SELECT c.id AS c_id,
                      n.id AS n_id,
                      SUM(strength) AS Strength 
                 FROM SYNAPSES s
                 JOIN CONTEXTS c ON c.id = s.context_id
                 JOIN NEURONS n ON n.id IN (s.n1_id, s.n2_id)
             GROUP BY c.id, n.id) x ON x.c_id = c.id
                                   AND x.n_id = n.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have the following MySQL table structure: num field company phone website 1 Gas
I have three mysql table from same database Db1. Three tables have following columns.
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
I have a MySQL table with the following schema: +---------+---------+----------------------+------------+ | User ID |
I have a MySQL table with the following schema: +--------------+-------------+------+-----+---------+----------------+ | Field | Type
I have a MySQL innodb database at 1.9GB, showed by following command. SELECT table_schema
I have the following Mysql Table Order table status 0 - incomplete status 1
I have a following mysql table with a lot (3000+) of values: [id] [parent_id]
I have the following MySQL/InnoDB table. I added a compound index as the primary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.